Java InetAddress.getAllByName()被阻止

Java InetAddress.getAllByName()被阻止,java,android,c++,dns,inetaddress,Java,Android,C++,Dns,Inetaddress,我最近遇到了一个有线问题。我有一个安卓设备连接了wifi,我相信wifi很好。但安卓设备无法接入互联网。然后我发现DNS解析有问题,下面是我所做的 1。我编写了一个应用程序,它只调用MainActivity中的InetAddress.getAllByName(“www.google.com”)方法。 @覆盖 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.la

我最近遇到了一个有线问题。我有一个安卓设备连接了wifi,我相信wifi很好。但安卓设备无法接入互联网。然后我发现DNS解析有问题,下面是我所做的

1。我编写了一个应用程序,它只调用MainActivity中的
InetAddress.getAllByName(“www.google.com”)
方法。

@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
新线程(newrunnable()){
@凌驾
公开募捐{
试一试{
Log.d(“DNSTEST”,“此处>>>0”);
InetAddress[]addresses=InetAddress.getAllByName(“www.google.com”);
Log.d(“DNSTEST”,“此处>>>1”);
如果(地址!=null){
Log.d(“DNSTEST”,“此处>>>2”);
用于(InetAddress:地址){
Log.d(“DNSTEST”,“here>>>3”);
Log.d(“DNSTEST”,“address:+address.getHostAddress());
}
}
Log.d(“DNSTEST”,“此处>>>4”);
}捕获(未知后异常e){
e、 printStackTrace();
}
}
}).start();
}
以下是logcat输出:

2019-05-27 11:14:36.710 5204-5221/com.upward.dns D/DNSTEST: here >>> 0
如您所见,当执行
InetAddress.getAllByName(“www.google.com”)
时,它被阻止。


2。然后,我用C++编写了一个可执行的程序,试图直接在Android上执行是否被阻止。
/*
*dns.cpp
*
*创建日期:2019年5月27日
*作者:威尔·唐
*/
#包括
#包括
#包括

没关系!


3。然后用相同的C++代码编写了一个共享库,使用JNI让java调用C++代码。< /强> < /P>
#包括“com_up_dns_DNSTest.h”
#包括
#包括
#包括
#包括
#定义标记“DNSTEST”
#定义printf(…)\uuuuuandroid\ulog\uprint(android\ulog\udebug、TAG、VA\uargs)
JNIEXPORT void JNICALL Java\u com\u Upper\u dns\u DNSTest\u测试(JNIEnv*env、jobject对象、jint计数)
{
printf(“此处>>>0”);
struct hostent*hptr=gethostbyname(“www.google.com”);
printf(“此处>>>1”);
字符**pptr=hptr->h\u地址列表;
printf(“此处>>>2”);
char str[32]={0};
printf(“此处>>>3”);
对于(;*pptr!=nullptr;pptr++){
printf(“此处>>>4”);
printf(“地址:%s\n”,inet_ntop(hptr->h_addrtype,*pptr,str,sizeof(str));
}
printf(“完成”);
}
package com.upper.dns;
公共级DNSTest{
静止的{
系统加载库(“dns”);
}
公共本机无效测试();
}

坏消息,它被封锁了。谁能给我一些建议吗?谢谢

还有一件事,当我重新启动android设备时,一切都很好。您是否遇到其他异常,如SecurityException?您的代码看起来正常。请更改
catch
以捕获所有异常,以便您可以记录它。然后重试。@user1506104没有引发任何异常,只是被阻止了。@selbie谢谢你的建议,代码只是被阻止了,没有引发任何异常。
2019-05-27 11:41:18.694 5860-5860/com.upward.dns D/DNSTEST_JNI: here >>> 0