转自http://www.cnblogs.com/ffvsff/archive/2008/05/18/1201874.html
感谢ffvsff
import java.net.InetAddress;
import java.net.UnknownHostException;
public class GetIP {
public static void main(String[] args) throws UnknownHostException
{
InetAddress inet = InetAddress.getLocalHost();
System.out.println("本机的ip=" + inet.getHostAddress());
}
}