如何在选定的服务器和端口上创建数据包嗅探器?像Wpe Pro或RPE之类的东西,但是我想使用Python和'print'来编写这些数据包。我试过这个:
import socket
UDP_IP = "xx.xx.xx.xx"
UDP_PORT = xxxx
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print("received message:", data)
但我认为它不起作用(UDP或其他什么是错的?)。我怎么能正确地做到这一点?
答案 0 :(得分:0)
我有工作代码发送然后接收,它有点像这样:
# set up the UDP socket
connection = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
connection.settimeout(5)
# Send packet by UDP
connection.sendto(request_bytes, (UDP_IP, UDP_PORT))
# Receive response packet
response_bytes = connection.recv(4096)
可能是您遗失settimeout
吗?
答案 1 :(得分:0)