📄 nslookupapp.java
字号:
package net;
import java.net.*;
import javax.swing.*;
public class NSLookupApp {
public static void main(String[] args) {
try {
String domainName=JOptionPane.showInputDialog
(null, "输入主机域名:","网络",JOptionPane.INFORMATION_MESSAGE);
try {
if(domainName.equals(""))
return;
else{
InetAddress host=InetAddress.getByName(domainName);
String hostName=host.getHostName();
// byte ipAddress[]=host.getAddress();
// String strIPAddress="";
// for(int i=0;i<ipAddress.length;i++){
// if(i!=ipAddress.length-1)
// strIPAddress=strIPAddress+((ipAddress[i]+256)%256)+".";
// else
// strIPAddress=strIPAddress+((ipAddress[i]+256)%256);
// }
String strIPAddress=host.getHostAddress();
JOptionPane.showMessageDialog(null, "主机名:"+hostName+"\n"+"IP地址:"+strIPAddress,"域名解析结果",JOptionPane.INFORMATION_MESSAGE);
}
} catch (RuntimeException e) {
JOptionPane.showMessageDialog(null, "你单击了取消按钮!","提示信息",JOptionPane.ERROR_MESSAGE);
}
} catch (UnknownHostException e) {
JOptionPane.showMessageDialog(null, "未知主机异常!","提示信息",JOptionPane.ERROR_MESSAGE);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -