import java.net.*; import java.util.*; /** *
Lists the IP interfaces defined on the system using the Java NetworkInterface.
*alexis.grandemange@pagebox.net
*Copyright (c) 2003 Alexis Grandemange
*This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; version 2.1 of the * License. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * A copy of the GNU Lesser General Public License lesser.txt should be * included in the distribution.* @author Alexis Grandemange * @version 0, 0, 1 */ public class Ipconfig { Ipconfig() throws Exception { Enumeration en = NetworkInterface.getNetworkInterfaces(); while(en.hasMoreElements()) { NetworkInterface ni = (NetworkInterface)en.nextElement(); Enumeration en2 = ni.getInetAddresses(); while(en2.hasMoreElements()) { InetAddress ia = (InetAddress)en2.nextElement(); System.out.println("Interface name:" + ni.getName() + " display name:" + ni.getDisplayName() + " " + ia.getHostAddress()); } } } public static void main(String[] args) throws Exception { new Ipconfig(); } }