62,616
社区成员
发帖
与我相关
我的任务
分享
try {
java.net.InetAddress test = java.net.InetAddress.getByName("localhost") ;
System.out.println(test.getLocalHost().getHostAddress());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public static void main(String[] args) throws Exception {
InetAddress addr = InetAddress.getLocalHost();
System.out.println(addr.getHostAddress());
}
// output 192.168.1.194
Enumeration<NetworkInterface> e=NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements())
{
System.out.println(e.nextElement());
}