InetAddress.getByName在代理后面失败 [英] InetAddress.getByName fails behind proxy

查看:198
本文介绍了InetAddress.getByName在代理后面失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将主机名解析为其相应的IP.

I'm trying to resolve a host name to its' corresponding IP.

我的环境是公司网络中代理服务器后面的Mac,该代理服务器通过系统偏好设置(自动代理配置)配置了.pac文件.到目前为止,一切工作正常,我可以访问公司网络内部和外部的资源.

My environment is a mac in a corporate network behind a proxy server, which is configured with a .pac file via the system preferences (automatic proxy configuration). So far everything is working fine and I can access resources inside and outside my corporate network.

解析网络中的主机非常正常: InetAddress.getByName("host.local");

Resolving hosts within my network works perfectly fine: InetAddress.getByName("host.local");

但是当我使用外部主机名时,出现UnknownHostException: InetAddress.getByName("google.com");

But when I use external host names, I get a UnknownHostException: InetAddress.getByName("google.com");

产生

Exception in thread "main" java.net.UnknownHostException: google.com
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1154)
    at java.net.InetAddress.getAllByName(InetAddress.java:1084)
    at java.net.InetAddress.getAllByName(InetAddress.java:1020)
    at java.net.InetAddress.getByName(InetAddress.java:970)
    at Test.main(Test.java:67)

(我对Inet6AddressImpl感到有些惊讶)

据我了解,InetAddress.getByName使用本机机制来解析主机名.因此,我认为该错误不是由Java jvm中缺少代理配置引起的.

As far as I understand is InetAddress.getByName using the native mechanisms to resolve host names. So I don't think that the error is caused by a missing proxy configuration within the java jvm.

但是,如果其他一切都正常的话,那还能是什么呢?

But what else can it be, if everything else is working fine?

一些(也许)有用的附加信息:

Some (maybe) useful additional information:

  • 我使用的是MacBook,ifconfig显示的接口lo0,gif0,stf0,en0,fw0,en1->已连接到网络,具有ipv4地址.

  • I'm using a MacBook, ifconfig shows the interfaces lo0, gif0, stf0, en0, fw0, en1 -> connected to the network, with ipv4 address.

nslookup google.com返回** server can't find google.com: NXDOMAIN

网络中Windows计算机上的相同代码产生了相同的异常

The same code on a windows machine within the network produced the same Exception

关于此错误原因的任何想法吗? 还是有其他方法可以解析Java中的主机名?

Any ideas about the cause of this error? Or are there other ways to resolve host names in java?

推荐答案

您的公司DNS服务器阻止您解析任何Interent域(他们可能不希望人们浏览非公司上下文).

Your corporate DNS server prevents you from resolving any Interent domain ( they probably do not want people browsing non-corporate context ).

nslookup查询失败的事实支持了这一点.

This is supported by the fact that your nslookup query fails.

如果您对公司政策没有投票权,而您的开发机器必须留在公司场所,则您无能为力.

If you don't have a vote on your corporate policy, and your development machine has to stay on your company premises, there is nothing that you can do.

这篇关于InetAddress.getByName在代理后面失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆