Exemplo n.º 1
0
import socket
from mylib import log
from struct import pack, unpack
import time
from traceback import format_exc
import os,re
from mylib.config import CONF

address = (CONF.getServer(),8983)

IP = None

def getIP():
    inf = os.popen('ipconfig')
    ipcfg = inf.readlines()
    for i in xrange(len(ipcfg)):
        lineinf = re.findall('^\s+IP[^:]+: ([^\r]+)\s$', ipcfg[i])   
        if lineinf and re.findall('^\s+[^:]+: ([^\r]+)\s$', ipcfg[i + 2]):
            return re.split('\.', lineinf[0])[-1]

class testClt():
    def __init__(self, sock):
        self.sock = sock
        self.switch = True
        self.pingQueue = []
        self.i = 0
        
    def makeHeart(self, number):
        return pack('<HHLH',10,0x9527,number,IP)
    
    def send(self):
Exemplo n.º 2
0
        string = pack("<HLHHL%ss" % len_msg_data, #第一和第二字段宽度对换
                      len_msg_data + 12, #12 = 4+2+2+2+4-2
                      0xAAAC, # magic code
                      len_msg_data + 12,
                      0x9001,
                      0,
                      msg_data)
        self.socket.sendall(string)

if __name__ == '__main__':
    log.run_log()
    log.uuid_log()
    runCMD('title test_manage')
    PORT = CONF.getPort()
    GMPORT = CONF.getGMPort()
    SERVER = CONF.getServer()
    PATH = CONF.getCltPath()
    USER = CONF.getUser()
    PASSWD = CONF.getPasswd()
    DELAYKILL = CONF.getDelayKill()
    IP = _getIP()
    killProcess('heartTest_clt.exe')
    os.system('start /B heartTest_clt.exe')
    while 1:
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((SERVER, PORT))
            log.LOG.info('connecting ...')
            sock.settimeout(HEARTTIMEOUT)
            ManageClient(sock)
        except: