如何使用python发送字节(请举例!)

2024-09-28 01:22:43 发布

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

目前,我正在尝试用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

Tags: toimportipinput字节portas错误

热门问题