In the Nbrun/pctools/find directory there is a simple little 'C' utility that finds all the netburners
on th elocal network. My Son has been playing with Python and really likes the language for
traditional Web apps. So I decided to look at it for educational purposes.
My first useful program was a python version of find. Some might find it useful.
Would there be any value in a Python port to the Netburner?
#This finds all the netburners on the local network
#I'm not a very good python programmer this was
#just a quick hack to play with the python networking stuff.
#any suggestion on improving this would be welcome
import sys,socket, traceback, struct
host = '' # Bind to all interfaces
port = 20034
tfstruct = struct.Struct('!LB')
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind((host, port))
try:
data = struct.pack("!Lc",0x4255524E,'R')
s.sendto(data, ('<broadcast>', port))
s.settimeout(2)
while 1 :
message, address = s.recvfrom(8192)
print "Found NetBurner at", address[0] #probably want to add to a list
except socket.error:
errno, errstr = sys.exc_info()[:2]
if errno == socket.timeout:
sys.exit() # Could return here or something else
raise
except:
traceback.print_exc()