在加入GE之前没怎么写过JAVA程序, 其实JAVA挺好的, API多, 而且跨平台, 并且速度也不慢 (已经优化很多了).
最近用到了 iNetAddress 这个库, 写了一命令行工具, 可以简易根据域名查询 IP 地址.
代码也在 https://github.com/DoctorLai/DNSLookup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import java.net.InetAddress; import java.net.UnknownHostException; public class DNSLookup { // https://helloacm.com/the-dns-lookup-tool-in-java-inetaddress/ public static void main(String args[]) { try { InetAddress host; if (args.length == 0) { host = InetAddress.getLocalHost(); displayHost(host); } else { for (int i = 0; i < args.length; ++ i) { host = InetAddress.getByName(args[i]); displayHost(host); } } } catch (UnknownHostException e) { e.printStackTrace(); } } private static void displayHost(InetAddress host) { System.out.println("Host:'" + host.getHostName() + "' has address: " + host.getHostAddress()); } } |
import java.net.InetAddress; import java.net.UnknownHostException; public class DNSLookup { // https://helloacm.com/the-dns-lookup-tool-in-java-inetaddress/ public static void main(String args[]) { try { InetAddress host; if (args.length == 0) { host = InetAddress.getLocalHost(); displayHost(host); } else { for (int i = 0; i < args.length; ++ i) { host = InetAddress.getByName(args[i]); displayHost(host); } } } catch (UnknownHostException e) { e.printStackTrace(); } } private static void displayHost(InetAddress host) { System.out.println("Host:'" + host.getHostName() + "' has address: " + host.getHostAddress()); } }
通过 javac DNSLookup.java 命令编译成 DNSLookup.class (或者下载 提前编译好的). 然后就可以通过以下例子来查询一个或者多个域名了
# java DNSLookup Host:'HP-PC' has address: 192.168.0.102 HP@HP-PC D:\ # java DNSLookup localhost Host:'localhost' has address: 127.0.0.1 HP@HP-PC D:\ # java DNSLookup localhost www.google.com Host:'localhost' has address: 127.0.0.1 Host:'www.google.com' has address: 216.58.201.36
简单好用.
英文: The DNS Lookup Tool in Java (InetAddress)
GD Star Rating
loading...
本文一共 115 个汉字, 你数一下对不对.loading...
上一篇: 微信小技巧: 怎么样清理僵尸粉(看看谁删除了你)
下一篇: 视频下载API遭受 DDOS攻击
扫描二维码,分享本文到微信朋友圈
