package checksomething;
import java.net.*;
public class GetIP {
public static String URL;
GetIP(String URL){
GetIP.URL=URL;
}
public String lookip() {
InetAddress address=null;
String IP=null;
try {
address=InetAddress.getByName(URL);
IP=address.getHostAddress();
}catch(UnknownHostException e) {
System.exit(2);
}
return IP;
}
public String lookname() {
InetAddress address1=null;
String name=null;
try {
address1=InetAddress.getByName(URL);
name=address1.getHostName();
}catch(UnknownHostException e) {
System.exit(2);
}
return name;
}
public static void main(String[] args) {
GetIP it=new GetIP("space.bilibili.com");
System.out.println(it.lookip());
System.out.println(it.lookname());
}
}
JAVA程序:查询网站IP地址
最新推荐文章于 2024-01-11 14:45:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)