从Python DGS获取目标IP和端口

2024-04-27 00:55:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python中有以下UDP/DGRAMsocket

sock.bind((UDP_IP, UDP_PORT))

while True:
    data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
    print "received message:", data

此代码正在代理服务器中运行,因此目标IP和端口与套接字不匹配。我正在使用tproxy截获数据包。你知道吗

如何获取目标IP和端口,而不是源IP和端口?你知道吗


Tags: 端口iptrue目标datasizebindport
1条回答
网友
1楼 · 发布于 2024-04-27 00:55:21

^{}

Return the socket’s own address. This is useful to find out the port number of an IPv4/v6 socket, for instance.

所以你想打印出sock.getsockname()

相关问题 更多 >