Question

I'm trying to create a simple thingermajigger in python at the moment just to test out sending UDP packets over a socket. I think that I'm getting my script perfectly fine other than using the socket.sendto command. I keep getting errors regarding the portion where "bytes" would go... either TypeError: an interget is required, or when I make it an interget TypeError: a string is required. Could someone provide me with an example of how to send a byte?

the point in my script where I'm getting the error is as follows... please fill out an example as well as a possible explanation / documentation for a newbie.

#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
Was it helpful?

Solution

In your posted code, port is a str, you should use port = int(input())

Aside: b'0x2E' which you had in the original question is 4 characters. If you mean chr(0x2E) you can also write '\x2E'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top