package org.InetAddressDemo;
import java.net.InetAddress;
public class InetAddressDemo {
public static void main(String[] args) throws Exception{
InetAddress locAdd = null;
InetAddress remAdd = null;
locAdd = InetAddress.getLocalHost();
remAdd = InetAddress.getByName("www.hut.edu.cn");
System.out.println("本机IP地址:"+locAdd.getHostAddress());
System.out.println("hut的IP地址:"+remAdd.getHostAddress());
System.out.println("本机是否可达到:"+locAdd.isReachable(5000));
}
}
Java网络编程(InetAddress)
时间: 2024-10-14 12:24:51