-
#!/usr/bin/python
-
-
from struct import *
-
from socket import *
-
from sys import *
-
-
class DBPkgHead:
-
def __init__(self):
-
self.Length = 47
-
def SetLength(self, length):
-
self.Length = length
-
def GetLength(self):
-
return self.Lenght
-
def GetStr(self):
-
self.s = pack('!H', self.Length)
-
self.s += pack('!B', 0)
-
self.s += pack('!H', 0)
-
self.s += pack('!I', 0)
-
self.s += pack('!H', 0)
-
self.s += pack('!I', 0)
-
self.s += pack('!H', 0)
-
self.s += pack('!I', 0)
-
self.s += pack('!H', 0)
-
self.s += pack('!B', 0)
-
self.s += pack('!B', 0)
-
self.s += pack('!H', 0)
-
return self.s
-
-
class RelayPkgHead:
-
def __init__(self):
-
pass
-
def GetStr(self):
-
self.s = pack('!H', 0)
-
self.s += pack('!H', 0)
-
self.s += pack('!H', 0)
-
self.s += pack('!H', 0)
-
return self.s
-
-
class CldPkgHead:
-
def __init__(self):
-
self.Command = 0
-
def SetCommand(self, cmd):
-
self.Command = cmd
-
def GetCommand(self):
-
return self.Command
-
def GetStr(self):
-
self.s = pack('!H', 0)
-
self.s += pack('!H', self.Command)
-
self.s += pack('!H', 0)
-
self.s += pack('!I', 0)
-
return self.s
-
-
class ServerPkg:
-
def __init__(self):
-
self.Head = 0x0A
-
self.DBPkgHead = DBPkgHead()
-
self.RelayPkgHead = RelayPkgHead()
-
self.CldPkgHead = CldPkgHead()
-
self.Body = ''
-
self.Tail = 0x03
-
def SetBody(self, body):
-
self.Body = body
-
self.DBPkgHead.SetLength(47 + len(body))
-
def SetCommand(self, cmd):
-
self.CldPkgHead.SetCommand(cmd)
-
def GetPkg(self):
-
return pack('!B', self.Head) + self.DBPkgHead.GetStr() + self.RelayPkgHead.GetStr() \
-
+ self.CldPkgHead.GetStr() + self.Body + pack('!B', self.Tail)
-
-
dest = ('172.27.12.141', 35000)
-
-
def Useage(prog):
-
print 'Room enter times proto tool'
-
print 'Useage: %s CmdID Uin RoomID' % prog
-
print ' CmdID'
-
print ' 1: Get Uin\'s RoomID enter times'
-
print ' 2: Increase Uin\'s RoomID enter times'
-
-
def main():
-
if len(argv) != 4:
-
Useage(argv[0])
-
exit(-1)
-
pkg = ServerPkg()
-
pkg.SetCommand(0x018C)
-
cmd = int(argv[1])
-
uin = int(argv[2])
-
room = int(argv[3])
-
body = pack('!BII', cmd, uin, room)
-
pkg.SetBody(body)
-
sock = socket(AF_INET, SOCK_DGRAM)
-
sock.sendto(pkg.GetPkg(), dest)
-
if cmd == 2:
-
exit(0)
-
s, src = sock.recvfrom(2048)
-
res = s[46:len(s)-1]
-
cmd, result, uin, room, times, = unpack('!BBIIH', res)
-
print 'Cmd\t%u' % cmd
-
print 'Result\t%u' % result
-
print 'Uin\t%u' % uin
-
print 'Room\t%u' % room
-
print 'Times\t%u' % times
-
-
if __name__ == "__main__":
-
main()
阅读(463) | 评论(0) | 转发(0) |