我正在构建一个android应用程序,如果用户要阻止facebook,则需要阻止来自某个应用程序示例的特定流量,然后不应从任何浏览器或facebook应用程序打开它。
搜索后,我得到了https://github.com/LipiLee/ToyShark。因此,我创建了一个VPN服务,并能够通过数据包解析从数据包中获取IP地址,但是我需要将IP转换为主机名,例如 192.xx.xx.xx至www.facebook.com 所以我用
try {
hostname = InetAddress.getByName(myIp).getHostName();
Log.w("Host for ", myIp + " is " + hostname) ;
}catch (UnknownHostException e){
Log.w("Unknown Host for ", myIp);
}
但是我得到
W / Host for:172.217.3.33是iad23s57-in-f1.1e100.net
W / Host对于:216.58.217.142是iad23s43-in-f14.1e100.net。 。
我试图为此使用MiniDNS库。
ResolverResult<A> result = DnssecResolverApi.INSTANCE.resolve(hostname, A.class);
if (!result.wasSuccessful()) {
DnsMessage.RESPONSE_CODE responseCode = result.getResponseCode();
// Perform error handling.
Log.d(TAG, “ Result Not successful");
return;
}
if (!result.isAuthenticData()) {
// Response was not secured with DNSSEC.
Log.d(TAG, ”Result Not authentic");
return;
}
Set<A> answers = result.getAnswers();
for (A a : answers) {
InetAddress inetAddress = a.getInetAddress();
// Do someting with the InetAddress, e.g. connect to.
Log.d(TAG, InetAddress.toString());
}
但出现错误
Access denied finding property "net.dns1"
所以我想问..
1.Is there any way to get the hostname from the packet other than the destination ip?
2.How to do DNS resolution in android to get hostname if i have only ip address?