A machine can have many IP addresses. The following will enumerate all adapters and show the address(es) for each adapter:
Enumeration<NetworkInterface> i = NetworkInterface.getNetworkInterfaces();
while(i.hasMoreElements())
{
NetworkInterface n = i.nextElement();
System.out.println(n.getName());
Enumeration<InetAddress> ea = n.getInetAddresses();
while(ea.hasMoreElements())
{
InetAddress a = ea.nextElement();
System.out.println(" "+a.toString());
}
}
It's up to you to figure out which adapter(s) and address(es) you're interested in.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…