/**
* 本实例演示获取本机计算机名+ip地址
* @author MichaelShi
*
*/
public class GetLocalHost {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
InetAddress myIP = null;
try {
myIP = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("IP:" + myIP);
}
System.out.println("myIP:" + myIP);
}
}
运行结果:myIP:MichaelShi-PC/130.251.9.160