在加入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)
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK