dnsjava 解析域名IP,支持ipv6
作者:
马克_唐卡 | 来源:发表于
2020-03-24 18:56 被阅读0次
前奏:安装依赖……
直接代码:
fun dnsResolver(url: String, isIpv4: Boolean): ArrayList<String> {
val ips = ArrayList<String>()
val resolver = SimpleResolver("114.114.114.114")
// 此处决定ip类型
val lookup = Lookup(url, if(isIpv4) Type.A else Type.AAAA)
lookup.setResolver(resolver)
val cache = Cache()
lookup.setCache(cache)
lookup.run()
if (lookup.getResult() === Lookup.SUCCESSFUL) {
val records = lookup.getAnswers()
for (record in records) {
ips.add(record.rdataToString())
}
}
return ips
}
本文标题:dnsjava 解析域名IP,支持ipv6
本文链接:https://www.haomeiwen.com/subject/hnjayhtx.html
网友评论