pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by frymaster on Fri 4th Dec 15:11
download | new post

  1. #!/usr/local/bin/python26
  2. import socket,ssl,time,select,time,struct,sys,select,collections
  3. import Mumble_pb2
  4.  
  5. headerFormat=">HI"
  6. messageLookupMessage={Mumble_pb2.Version:0,Mumble_pb2.UDPTunnel:1,Mumble_pb2.Authenticate:2,Mumble_pb2.Ping:3,Mumble_pb2.Reject:4,Mumble_pb2.ServerSync:5,
  7.         Mumble_pb2.ChannelRemove:6,Mumble_pb2.ChannelState:7,Mumble_pb2.UserRemove:8,Mumble_pb2.UserState:9,Mumble_pb2.BanList:10,Mumble_pb2.TextMessage:11,Mumble_pb2.PermissionDenied:12,
  8.         Mumble_pb2.ACL:13,Mumble_pb2.QueryUsers:14,Mumble_pb2.CryptSetup:15,Mumble_pb2.ContextActionAdd:16,Mumble_pb2.ContextAction:17,Mumble_pb2.UserList:18,Mumble_pb2.VoiceTarget:19,
  9.         Mumble_pb2.PermissionQuery:20,Mumble_pb2.CodecVersion:21}
  10.  
  11. messageLookupNumber={}
  12.  
  13. insaneBuffer=collections.deque()
  14. sendBuffer=""
  15. s = open("server.cap","w")
  16.  
  17. for i in messageLookupMessage.keys():
  18.         messageLookupNumber[messageLookupMessage[i]]=i
  19.  
  20. host=("127001.org",31337)
  21. protocol=ssl.PROTOCOL_TLSv1
  22. listensock=socket.socket(type=socket.SOCK_STREAM)
  23. ssl2=ssl.wrap_socket(listensock,ssl_version=protocol,certfile="cert.pem")
  24. ssl2.bind(("10.127.0.1",31338))
  25. ssl2.listen(1)
  26. ssl3,address=ssl2.accept()
  27. print "connected to " + str(address)
  28.  
  29. TCPsock=socket.socket(type=socket.SOCK_STREAM)
  30. sslSock=ssl.wrap_socket(TCPsock,ssl_version=protocol)
  31. print "trying to connect"
  32. sslSock.connect(host)
  33. print "connected"
  34. a=ssl3.fileno()
  35. b=sslSock.fileno()
  36. aFile=open("client.cap","w")
  37. bFile=open("server.cap","w")
  38. aaFile=open("clientSpeech.cap","w")
  39. bbFile=open("serverSpeech.cap","w")
  40.  
  41. def decodeMessage(msgType,messageString):
  42.         msgClass=messageLookupNumber[msgType]
  43.         message=msgClass()
  44.         message.ParseFromString(messageString)
  45.         return str(type(message)) + str(message)
  46.  
  47. def receiveMessage(conn,passthru,decoded,raw,comment):
  48.         meta = conn.recv(6)
  49.         if len(meta)!=6:
  50.                 print str(len(meta)) + " received, bugger this for a game of soldiers"
  51.                 sys.exit(0)
  52.         type,length=struct.unpack(headerFormat,meta)
  53.         stringMessage=conn.recv(length)
  54.         if len(stringMessage)!=length:
  55.                 print "Expecting message of length " + str(length) + " and got " + str(len(stringMessage)) +" , sod this I'm off"
  56.                 sys.exit(0)
  57.         passthru.write(meta+stringMessage)
  58.         if type==1:
  59.                 decoded.write("Speech packet\n")
  60.                 raw.write("XXX" + stringMessage)
  61.                 return
  62.         print comment,type,decodeMessage(type,stringMessage)
  63.         decoded.write(decodeMessage(type,stringMessage)+"\n")
  64.  
  65.  
  66. while True:
  67.         stuff,nonsense,nonsense2 = select.select((a,b),(),(),0.5)
  68.         if a in stuff:
  69.                 receiveMessage(ssl3,sslSock,aFile,aaFile,"CLIENT")
  70.         if b in stuff:
  71.                 receiveMessage(sslSock,ssl3,bFile,bbFile,"SERVER")

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings