目前,我正在尝试用python创建一个简单的thingermajigger来测试通过套接字发送UDP包。我觉得除了使用插座.sendto命令。我一直收到关于“字节”的部分的错误。。。要么是TypeError:integrat是必需的,要么是当我把它变成interget TypeError:a string是必需的。有人能给我举一个如何发送字节的例子吗?在
在我的脚本中,我得到错误的地方如下。。。请为新手填写一个示例以及可能的解释/文档。在
#full script as requested
import socket
import random
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
butes = random._urandom(1024)
#originally found this as a way to generate bytes to send, but it didn't work out
print("target IP: ")
ip = input()
print("port: ")
port = input()
while 1:
sock.sendto(butes, (ip, port))
print("Sent %s amount of packets to %s at port %s." % (sent,ip,port))
sent += 1
在您发布的代码中,
port
是str
,您应该使用port = int(input())
另外:
b'0x2E'
你在原问题中有4个字符。如果你的意思是chr(0x2E)
,你也可以写'\x2E'
相关问题 更多 >
编程相关推荐