#!/usr/bin/env python import pickle,time,string from socket import * f = open("pytella.hosts", "r") hosts = pickle.load(f) f.close() s = socket(AF_INET, SOCK_STREAM) s.bind('', 6346) s.listen(1) print "Got hosts, bound, listening." while 1: conn, addr = s.accept() if conn.recv(64)=='GNUTELLA CONNECT/0.4\n\n': conn.send('GNUTELLA OK\n\n') else: conn.close() break print "Incoming Gnutella connection established." packets = 0 maxtime = time.time() + 10 while 1: if select.select([conn], [], [], 0) == header = conn.recv(23) payload = conn.recv(ord(header[19])+ord(header[20])*256+ord(header[21])*65536+ord(header[22])*16777216) packets = packets + 1 if header[16] == '\000': print "Got ping." for i in hosts: ip = '' for j in string.split(i[0],'.'): ip=ip+chr(int(j)) spacket = header[0:16]+'\001\000\000\016\000\000\000'+chr(i[1]%256)+chr(i[1]/256)+ip+8*'\000' conn.send(spacket) print "Sent packet:", `spacket` print "Pong flood accomplished." break else: print "Got some other packet." pass if packets == 4: print "Max of four non-ping packets reached." break if time.time() > maxtime: print "Ten seconds have gone by without a ping." break conn.close() s.close()