Exemplo n.º 1
0
def save_reboot(ip, port, ver=2):
    try:
        address = (ip, port)
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.settimeout(5)
        header, save = pkg.get_pair(0x0d, ver)
        send_cmd(s, address, header, save)
        raw, address = s.recvfrom(1024)
        header, body = pkg.unpack(raw, 2)
        import time
        time.sleep(1)
        header, reboot = pkg.get_pair(0x0c, ver)
        send_cmd(s, address, header, reboot)
        raw, address = s.recvfrom(1024)
        header, body = pkg.unpack(raw, 2)
        s.close()
    except Exception, e:
        logger.error(e)
        return False
Exemplo n.º 2
0
def setinforsp(ip, port, cmd, ver=2, body_dict=None):
    try:
        address = (ip, port)
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.settimeout(2)
        header, body = pkg.get_pair(cmd, ver)
        if body_dict:
            body.load_from_dict(body_dict)
        send_cmd(s, address, header, body)
        raw, address = s.recvfrom(1024)
        header, body = pkg.unpack(raw, ver)
        s.close()
        if header.ret == 0:
            return True
        else:
            return False
    except Exception, e:
        logger.error(e)
        return False