gpt4 book ai didi

linux - UDP 连接被拒绝

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:59 26 4
gpt4 key购买 nike

这就是我想要做的:

我有一台 Windows 计算机和一台 Linux 计算机 (ubuntu 16.10) 连接到同一个无线路由器。路由器连接到 Internet,因为这可能会引发一些安全问题(我们不希望 Windows 计算机与网络通信)。

Windows 计算机正在运行一个程序,该程序应该将数据流式传输到 UPD 端口(例如端口 1234)。使用 Microsoft TCPView 实用程序,我可以看到 Windows 机器打开了端口。事实上,它应该允许来自任何 IP 地址和任何端口的连接(这就是 TCPView 中 * 的含义)。

View of the TCPView Utility

当我尝试使用 nmap 从 Linux 计算机上查找 Windows 计算机上的开放端口时,会发生以下情况:

Starting Nmap 7.01 ( https://nmap.org ) at 2017-01-30 16:50 EST
Nmap scan report for 192.168.0.164
Host is up (0.051s latency).
PORT STATE SERVICE
1510/udp open|filtered mvx-lm
MAC Address: 74:DE:2B:D8:26:24 (Liteon Technology)

至少,这告诉我 linux 机器可以看到 windows 机器(我也可以 ping 通它)。但是,我不确定端口的open|filtered 状态。根据 Nmap 手册:

Nmap places ports in this state when it is unable to determine whether
a port is open or filtered. This occurs for scan types in which open ports give no response. The lack of response could also mean that a packet filter dropped the probe or any response it elicited. So Nmap does not know for sure whether the port is open or being filtered. The UDP, IP protocol, FIN, NULL, and Xmas scans classify ports this way.

当我尝试使用 Python 连接到端口时,出现错误。这段代码

import socket
UDP_IP = "192.168.0.164"
UDP_PORT = 1234
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))

导致错误“连接被拒绝”。一个应该读取流数据的小 C++ 客户端程序也无法连接到端口。我现在正在使用 Python 来更快地测试端口的可访问性。

相比之下,连接到 TCP 端口 8080 工作正常。此外,我一直在通过 TCP 通过同一路由器在其他机器之间来回发送数据并使用一系列端口。

其他重要信息:

  • 如果我关闭 windows 机器上的防火墙和病毒扫描程序,也会出现同样的错误
  • 我在 Windows 的高级防火墙设置中添加了 UDP 端口 1234 作为允许的连接。

所以,我的问题是:

  • 有人对如何调试/解决这种情况有什么建议吗?
  • UDP 和 TCP 之间有什么不同会导致 TCP 正常工作(在我过去的项目中)并导致 UDP 给我做噩梦?

最佳答案

您忘记了 UDP 不是基于连接的协议(protocol)。它是一种数据报协议(protocol)。

无法区分正在接收 UDP 数据包但不响应它们的服务器与位于防火墙后面并丢弃这些数据包的服务器。这就是 nmap 将端口描述为 open|filtered 的原因——它无法区分两者之间的区别。

您对 sock.bind 的调用失败,因为您正试图绑定(bind)(即开始监听数据包!)到远程 IP 上的端口。这在一般情况下是不可能的。

关于linux - UDP 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41948410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com