java中关于ip的使用
java中关于ip的类在java.net.InetAddress下,可以查看文档找到自己想用的。
部分实现代码:
public class lesson01 {
public static void main(String[] args) throws UnknownHostException {
InetAddress byName = InetAddress.getByName("DESKTOP-6MRGC4H");
System.out.println(byName);
InetAddress byName2 = InetAddress.getByName("www.baidu.com");
System.out.println(byName2);
InetAddress byName3 = InetAddress.getLocalHost();
System.out.println(byName3);
}
}