在java的net包中,提供了InetAddress,可以用来获得本机的IP地址:
String ipAddress = null;
//get the server's ipAddress
try{
ipAddress = InetAddress.getLocalHost().getHostAddress();
}catch(UnknownHostException e){}
String ipAddress = null;
//get the server's ipAddress
try{
ipAddress = InetAddress.getLocalHost().getHostAddress();
}catch(UnknownHostException e){}