简体   繁体   English

无法连接到C主机:Windows,DNS上找不到主机名(11001)问题?

[英]Cannot connect to host in C: Hostname not found (11001) on Windows, DNS Problem?

I am trying to use an API that connects to a remote server in C, but I keep having the following error message: 我正在尝试使用连接到C中的远程服务器的API,但是我始终收到以下错误消息:

log_message: 15:13:19.489 I [ap:1388] Connecting to AP A3.spotify.com:4070

log_message: 15:13:19.490 E [ap:1324] AP Socket Error: Hostname not found (11001)

log_message: 15:13:19.491 E [ap:3396] Connection error:  4

log_message: 15:13:19.491 I [ap:1388] Connecting to AP A1.spotify.com:80

As you can see with the dates, the error message is instantaneous, so I think something is blocking the messages locally on my computer. 正如您在日期中看到的那样,错误消息是瞬时的,因此我认为某些原因阻止了计算机上本地的消息。

Here is the TCP stream I captured with Wireshark: 这是我用Wireshark捕获的TCP流:

30  1.682802    MyLocalIp   193.182.8.15    HTTP    Continuation or non-HTTP traffic
31  1.702236    193.182.8.15    MyLocalIp   HTTP    Continuation or non-HTTP traffic
33  1.901706    MyLocalIp   193.182.8.15    TCP 50222 > http [ACK] Seq=12 Ack=12 Win=251 Len=0

So, according to Wireshark, the first message sent by my computer has an incorrect Header checksum. 因此,根据Wireshark,我的计算机发送的第一条消息的Header校验和不正确。

I know the host is correct, because when I use the same C API in Java with JNA, I have the following result: 我知道主机是正确的,因为当我在Java和JNA中使用相同的C API时,会得到以下结果:

log_message() called:15:46:48.718 I [ap:1388] Connecting to AP A1.spotify.com:4070

log_message() called:15:46:53.769 E [ap:1324] AP Socket Error: Undefined Error 0x4E20 (20000)

log_message() called:15:46:53.770 E [ap:3396] Connection error:  117

log_message() called:15:46:53.770 I [ap:1388] Connecting to AP A2.spotify.com:80

log_message() called:15:46:53.789 I [ap:938] Connected to AP: 193.182.8.12:80

So, here the connection fails on port 4070, which is normal because it is blocked by the company's firewall, and then it succeeds on port 80. 因此,此处的连接在端口4070上失败,这是正常的,因为它已被公司的防火墙阻止,然后在端口80上成功。

And here is the Wireshark capture for the Java version: 这是Java版本的Wireshark捕获:

104 6.296125    MyLocalIp   193.182.8.15    TCP 50339 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=8 SACK_PERM=1
107 6.575599    193.182.8.15    MyLocalIp   TCP http > 50339 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460 SACK_PERM=1 WS=7
108 6.575732    MyLocalIp   193.182.8.15    TCP 50339 > http [ACK] Seq=1 Ack=1 Win=65536 Len=0
109 6.582627    MyLocalIp   193.182.8.15    HTTP    Continuation or non-HTTP traffic
110 6.614789    193.182.8.15    MyLocalIp   TCP http > 50339 [ACK] Seq=1 Ack=512 Win=6912 Len=0
112 6.714201    193.182.8.15    MyLocalIp   HTTP    Continuation or non-HTTP traffic
113 6.722057    MyLocalIp   193.182.8.15    HTTP    Continuation or non-HTTP traffic
115 6.746484    193.182.8.15    MyLocalIp   TCP http > 50339 [ACK] Seq=500 Ack=677 Win=8064 Len=0
116 6.750938    193.182.8.15    MyLocalIp   HTTP    Continuation or non-HTTP traffic
117 6.751093    MyLocalIp   193.182.8.15    HTTP    Continuation or non-HTTP traffic
118 6.985366    193.182.8.15    MyLocalIp   HTTP    [TCP Retransmission] Continuation or non-HTTP traffic
119 6.985416    MyLocalIp   193.182.8.15    TCP [TCP Dup ACK 117#1] 50339 > http [ACK] Seq=787 Ack=544 Win=65024 Len=0 SLE=500 SRE=544
121 7.013666    193.182.8.15    MyLocalIp   HTTP    Continuation or non-HTTP traffic
124 7.213661    MyLocalIp   193.182.8.15    TCP 50339 > http [ACK] Seq=787 Ack=1803 Win=65536 Len=0
132 7.703708    MyLocalIp   193.182.8.15    HTTP    [TCP Retransmission] Continuation or non-HTTP traffic
133 7.721265    193.182.8.15    MyLocalIp   HTTP    Continuation or non-HTTP traffic

I tried adding the IP 193.182.8.15 in my System32/drivers/etc/hosts file for the hostname A1.spotify.com, A2.spotify.com and A3.spotify.com, but it didnt change anything. 我尝试在我的System32 / drivers / etc / hosts文件中为主机名A1.spotify.com,A2.spotify.com和A3.spotify.com添加IP 193.182.8.15,但它没有做任何更改。

I shut down the Windows firewall and antivirus, it didn't help either. 我关闭了Windows防火墙和防病毒软件,它也无济于事。

I tried running this at home without company proxy and firewall, but it was the same (except that on the Java version the service was able to connect on port 4070) 我尝试在没有公司代理和防火墙的情况下在家运行此服务器,但是它是相同的(除了在Java版本上,该服务能够在端口4070上连接)

Any idea? 任何想法?

Thanks! 谢谢!

Incorrect header checksums are not critical. 不正确的标头校验和并不重要。 Lots of software relies on the hardware re-computation of header checksums so they rarely pre-compute the header checksum in the CPU. 许多软件都依赖报头校验和的硬件重新计算,因此它们很少在CPU中预先计算报头校验和。 Since wireshark grabs the information before it goes to the chip that sends it out the wire, wireshark will report incorrect header checksums with some frequency. 由于wireshark会先获取信息,然后再将其发送到将其发送出去的芯片,因此wireshark将以一定频率报告错误的标头校验和。

Note that the original error was dealing with host A3, but some of your "proof" that machines were reachable was demonstrated with hosts A1 and A2. 请注意,最初的错误与主机A3有关,但是主机A1和A2证明了您的一些有关计算机可访问的“证明”。 Odds are good that these hosts do not share the same IP address, so I would be careful about "setting them all to XXXX" in the hosts file. 这些主机不共享相同的IP地址是件好事,因此在主机文件中“将它们全部设置为XXXX”时要格外小心。

Also note that bind clients can be configured to skip over host file entries. 还要注意,可以将绑定客户端配置为跳过主机文件条目。 I'm not sure that's the case here, but I would look to adding a public name server to the resolv.conf file (or equivalent) and see if you get better results. 我不确定情况是否如此,但我希望将公共名称服务器添加到resolv.conf文件(或等效文件)中,看看是否能获得更好的结果。 If the machine you ran on "at home" was the same laptop you used "at work" a bad resolv.conf file would have "traveled with you". 如果您在“在家”上运行的计算机与“在工作中”使用的笔记本电脑相同,则错误的resolv.conf文件将“随身携带”。

Good luck 祝好运

You didn't say which networking library you are using. 您没有说要使用哪个网络库。 Presumably a 3rd party or internal library. 大概是第三方或内部图书馆。
I'm going to take a wild guess, but I bet your networking library expects IP addresses and not DNS names? 我将做出一个疯狂的猜测,但是我敢打赌,您的网络库需要IP地址而不是DNS名称吗? Have you tried programming your app to just connect to "193.182.8.15" instead of "a3.spotify.com"? 您是否尝试过对应用程序进行编程,使其仅连接到“ 193.182.8.15”而不是“ a3.spotify.com”? If that works, do a gethostbyname call to resolve the DNS name to IP address. 如果可行,请执行gethostbyname调用以将DNS名称解析为IP地址。

Here's some other things to try 这是其他一些尝试

Type this from the command line: 从命令行输入:

ping a3.spotify.com

If successful, the result will look something like this: 如果成功,结果将如下所示:

Pinging a3.spotify.com [193.182.8.15] with 32 bytes of data:
Reply from 193.182.8.15: bytes=32 time=79ms TTL=49
Reply from 193.182.8.15: bytes=32 time=79ms TTL=49
Reply from 193.182.8.15: bytes=32 time=79ms TTL=49
Reply from 193.182.8.15: bytes=32 time=79ms TTL=49

Ping statistics for 193.182.8.15:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 79ms, Maximum = 79ms, Average = 79ms

The output of this program tells me two things. 该程序的输出告诉我两件事。

  1. That a3.spotify.com correctly resolves to 193.182.8.15. 该a3.spotify.com正确解析为193.182.8.15。 No hosts files hacks necessary. 无需主机文件黑客。 (Maybe on your corporate network you do need this). (也许在您的公司网络中确实需要此功能)。

  2. Since I got valid pings back, that means the host is likely reachable. 由于我收到了有效的ping命令,这意味着主机很可能可达。 But some machines are configured not to accept pings, so lack of a ping response it not a definitive answer. 但是某些计算机配置为不接受ping,因此缺少ping响应并不是确定的答案。 What is important to see if ping successfully resolved the hostname. 查看ping是否成功解析主机名很重要。

Now type this from the command line to test connectivity to port 80. 现在,从命令行键入此命令以测试与端口80的连接。

telnet a3.spotify.com 80 ( don't have telnet? see below ) telnet a3.spotify.com 80没有telnet?请参见下文

Does it "connect" (and jump to a blank screen)? 它是否“连接”(并跳至空白屏幕)? (Press CTRL+] to exit, followed by "quit") (按CTRL +]退出,然后按“退出”)

Do the same telnet, except for port 4070. 除端口4070外,执行相同的telnet。

ping and telnet are quick and dirty ways to test for DNS resolution and IP:port connectivity. ping和telnet是测试DNS解析度和IP:端口连接性的快捷方法。

These above commands may not work on your corporate network, because your firewall may require all traffic to go through a proxy. 以上这些命令可能无法在公司网络上使用,因为防火墙可能要求所有流量都通过代理。 Your browser at work is likely configured to work this way either via auto-detect or by admin install. 您的工作浏览器很可能配置为通过自动检测或管理员安装以这种方式工作。 If this is the case, then your app isn't likely to work on the corporate network - unless your networking library can be configured to use a proxy. 如果是这种情况,则您的应用程序不太可能在公司网络上运行-除非可以将您的网络库配置为使用代理。 (Some network libraries auto-detect or read your browser settings). (某些网络库会自动检测或读取您的浏览器设置)。

To install Telnet Client Click the Start button , click Control Panel, and then click Programs. 安装Telnet客户端的步骤单击“开始”按钮,单击“控制面板”,然后单击“程序”。

Under Programs and Features, click Turn Windows features on or off. 在“程序和功能”下,单击“打开或关闭Windows功能”。 If you are prompted for an administrator password or confirmation, type the password or provide confirmation. 如果提示您输入管理员密码或确认,请键入密码或提供确认。

In the Windows Features dialog box, select the Telnet Client check box. 在“ Windows功能”对话框中,选中“ Telnet客户端”复选框。

Click OK. 单击确定。 The installation might take several minutes. 安装可能需要几分钟。

我终于找到了解决方案:以管理员身份运行程序解决了问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM