import java.net.*;
public class IPDemo {
public static void main(String[] args) throws Exception
{
InetAddress i=InetAddress.getLocalHost();
/* * 输出本机的主机名和IP地址 */
//System.out.println(i.toString());
/* * 输出本机IP地址 */
//System.out.println("address:"+i.getHostAddress());
/* * 输出本机的主机名 */
//System.out.println("name:"+i.getHostName());
/* * 任意主机IP地址 */
InetAddress ia=InetAddress.getByName("192.168.3.125");
/* * 输出该本机的IP地址 */
System.out.println("address:"+i.getHostAddress());
/* * 输出该本机的主机名 */
System.out.println("name:"+i.getHostName());
}
}