java网络通信基础知识

try {
//获取本机的IP“地址对象”
InetAddress ip = InetAddress.getLocalHost();
// System.out.println(ip);
//获得对应IP的机器名:
System.out.println(ip.getHostName());
//获得对应IP对应IP字符串:
System.out.println(ip.getHostAddress());
System.out.println("-------------------------------");
//通过解析主机名获得IP
InetAddress byName = InetAddress.getByName("DESKTOP-A1IIHRH");//不区分大小写
System.out.println(byName);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

posted on 2018-05-03 15:27  爱河  阅读(130)  评论(0)    收藏  举报

导航