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

发布于 2024-10-21 15:14:30 字数 3258 浏览 1 评论 0原文

我正在尝试使用 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

正如您在日期中看到的那样,错误消息是瞬时的,所以我认为某些东西阻止了我本地的消息电脑。

这是我用 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

因此,根据 Wireshark 的说法,我的计算机发送的第一条消息的标头校验和不正确。

我知道主机是正确的,因为当我在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

所以,这里在端口4070上连接失败,这是正常的,因为它被公司的防火墙阻止了,然后它在端口 80 上成功。

这是 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

我尝试在我的 System32/drivers/etc/hosts 文件中为主机名 A1.spotify.com、A2.spotify.com 添加 IP 193.182.8.15 和A3.spotify.com,但它没有改变任何东西。

我关闭了Windows防火墙和防病毒软件,也没有帮助。

我尝试在没有公司代理和防火墙的情况下在家里运行它,但它是相同的(除了在 Java 版本上该服务能够在端口 4070 上连接)

有什么想法吗?

谢谢!

I am trying to use an API that connects to a remote server in C, but I keep having the following error message:

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:

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.

I know the host is correct, because when I use the same C API in Java with JNA, I have the following result:

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.

And here is the Wireshark capture for the Java version:

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.

I shut down the Windows firewall and antivirus, it didn't help either.

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)

Any idea?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终弃我 2024-10-28 15:14:30

错误的标头校验和并不重要。许多软件依赖于硬件重新计算标头校验和,因此它们很少在 CPU 中预先计算标头校验和。由于wireshark 在信息到达将其发送到线路的芯片之前获取信息,因此wireshark 会以一定的频率报告不正确的标头校验和。

请注意,最初的错误是在处理主机 A3 时出现的,但您的一些计算机可访问的“证据”已通过主机 A1 和 A2 进行了演示。这些主机很可能不共享相同的 IP 地址,因此我会小心地在主机文件中“将它们全部设置为 XXXX”。

另请注意,绑定客户端可以配置为跳过主机文件条目。我不确定这里的情况是否如此,但我希望将公共名称服务器添加到 resolv.conf 文件(或等效文件)中,看看是否能获得更好的结果。如果您“在家”运行的计算机与您“在工作”使用的同一台笔记本电脑相同,则错误的 resolv.conf 文件将“与您同行”。

祝你好运

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. 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.

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. Odds are good that these hosts do not share the same IP address, so I would be careful about "setting them all to X.X.X.X" in the hosts file.

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. 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".

Good luck

隐诗 2024-10-28 15:14:30

您没有说您正在使用哪个网络库。大概是第三方或内部库。
我将进行大胆的猜测,但我敢打赌您的网络库需要的是 IP 地址而不是 DNS 名称?您是否尝试过将应用程序编程为仅连接到“193.182.8.15”而不是“a3.spotify.com”?如果有效,请执行 gethostbyname 调用以将 DNS 名称解析为 IP 地址。

这里还有一些其他可以尝试的事情

从命令行键入:

ping a3.spotify.com

如果成功,结果将如下所示:

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

该程序的输出告诉我两件事。

  1. a3.spotify.com 正确解析为 193.182.8.15。无需修改主机文件。 (也许在您的公司网络上您确实需要这个)。

  2. 由于我收到了有效的 ping 回复,这意味着主机可能可以访问。但有些机器被配置为不接受 ping,因此缺少 ping 响应并不是一个明确的答案。重要的是要查看 ping 是否成功解析主机名。

现在从命令行输入此命令来测试与端口 80 的连接。

telnet a3.spotify.com 80没有 telnet?见下文

它是否“连接” (并跳到空白屏幕)? (按 CTRL+] 退出,然后按“退出”)

执行相同的 telnet,但端口 4070 除外。

ping 和 telnet 是测试 DNS 解析和 IP:端口连接的快速但肮脏的方法。

上述命令可能不适用于您的公司网络,因为您的防火墙可能要求所有流量都通过代理。您工作中的浏览器可能通过自动检测或管理员安装配置为以这种方式工作。如果是这种情况,那么您的应用程序不太可能在公司网络上运行 - 除非您的网络库可以配置为使用代理。 (某些网络库会自动检测或读取您的浏览器设置)。

要安装 Telnet 客户端,请单击
开始按钮,单击控制面板,
然后单击“程序”。

在程序和功能下,单击
打开或关闭 Windows 功能。如果
系统会提示您输入管理员身份
密码或确认,输入
密码或提供确认。

在 Windows 功能对话框中,
选中“Telnet 客户端”复选框。

单击“确定”。安装可能需要
几分钟。

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? Have you tried programming your app to just connect to "193.182.8.15" instead of "a3.spotify.com"? If that works, do a gethostbyname call to resolve the DNS name to IP address.

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. 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. But some machines are configured not to accept pings, so lack of a ping response it not a definitive answer. What is important to see if ping successfully resolved the hostname.

Now type this from the command line to test connectivity to port 80.

telnet a3.spotify.com 80 (don't have telnet? see below)

Does it "connect" (and jump to a blank screen)? (Press CTRL+] to exit, followed by "quit")

Do the same telnet, except for port 4070.

ping and telnet are quick and dirty ways to test for DNS resolution and IP:port connectivity.

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.

Under Programs and Features, click
Turn Windows features on or off. 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.

Click OK. The installation might take
several minutes.

琉璃繁缕 2024-10-28 15:14:30

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

I finally found the solution:
Running my program as Administrator solved the problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文