JAVA的IP
JAVA使用IP只有方法,没有类。这个方法名是:InetAddress。
.getAddress()//获取地址
.getHostAddress()//获取ip
.getHostName()//获取主机名
.getCanonicalHostName()//获取规范主机名
package IP; import java.net.InetAddress; import java.net.UnknownHostException; public class TestInetAddress { public static void main(String[] args) { InetAddress inetAddress = null; try { inetAddress = InetAddress.getByName("www.baidu.com"); } catch (UnknownHostException e) { e.printStackTrace(); } System.out.println(inetAddress);//包括地址的名和ip System.out.println(inetAddress.getAddress());//获取地址 System.out.println(inetAddress.getHostAddress());//获取ip System.out.println(inetAddress.getHostName());//获取主机名 System.out.println(inetAddress.getCanonicalHostName());//获取规范主机名 } }