0

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
Disconnect3d
  • 312
  • 1
  • 3
  • 11

1 Answers1

2

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'

John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • although the socket and such may also not be working correctly, at the moment I was focusing on being able to actually send the bytes... I keep recieveing an error message! i'm on python 3 by the way, if that makes a difference. – user2317808 May 09 '13 at 07:21
  • that's so strange... now it's working. I'm using a different computer so perhaps a tiny version change got rid of it and it was a bug. – user2317808 May 09 '13 at 11:51