import sys, socket, datetime,time # ecoute UDP port 7777 et reponse au mme port if len(sys.argv) != 2 : print "appel : sudo python "+sys.argv[0]+" port_a_ecouter" sys.exit() port=int(sys.argv[1]) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('',port)) print " Ecoute UDP port ", port," (frapper ^C pour abandonner)\n" alphabet="0123456789" while 1: (buf, address)=sock.recvfrom(2048) if len(buf)==0: break print datetime.datetime.now()," IP: " , address, buf fub="" n=len(buf)-1 compte=1 repet=0 for i in range (1,n+1) : un= buf[i] pw=alphabet.find(un) if ( pw<0): compte=0 if (compte==1) : repet=10*repet+ pw fub=fub +buf[n-i] #print i, n, buf[n-i], "donne ", fub print datetime.datetime.now()," IP: " , address, buf, ">" , fub , repet time.sleep(repet) sock.sendto( fub, address) print "done"