Esempio n. 1
0
    def request_messages(self):
        num_msg=0
        connection = http.client.HTTPConnection('192.168.0.179', 8080, timeout=10)
        headers = {'Content-type': 'application/json'}

        datos = {"direccion": ip.getIp(),"conexion": self.conexion}
        json_datos = json.dumps(datos)
        
        connection.request("GET", "/messages",json_datos,headers)
        response = connection.getresponse()
        datos = response.read().decode("utf-8")
        mensajes = json.loads(datos)
        if num_msg < len(mensajes):
            num_msg = len(mensajes)
            #system("clear")
            Tabla = """\
+---------------------------------------------------------------------+
|    Usuario-Hora                                Mensaje              |
|---------------------------------------------------------------------|
{}
+---------------------------------------------------------------------+\
"""
            Tabla = (Tabla.format('\n'.join("| {0:<30} {1:>36} |".format(fila["user"],fila["mensaje"])for fila in mensajes)))
            print (Tabla)
                


            connection.close()
Esempio n. 2
0
 def enviar(self, dato): 
                  
     fecha = time.strftime("%d/%m/%y")
     hora = time.strftime("%H:%M:%S")
     datos = {"direccion": ip.getIp(),"mensaje": dato, "fecha": fecha, "hora": hora}
     json_datos = json.dumps(datos)
     connection = http.client.HTTPConnection('192.168.0.179', 8080, timeout=10)
     connection.request('POST', '/add_message', json_datos, self.headers)
     connection.close()
Esempio n. 3
0
    def register_user(self,usuario):
        connection = http.client.HTTPConnection('192.168.0.179', 8080, timeout=10)
        headers = {'Content-type': 'application/json'}

        datos = {"direccion": ip.getIp(),"usuario":usuario}
        json_datos = json.dumps(datos)
        
        connection.request("POST", "/register",json_datos,headers)
        response = connection.getresponse()
        respuesta = response.read()
        a=respuesta.decode("utf-8")
        return a
Esempio n. 4
0
 def update_last_time(self):
     p=0
     connection = http.client.HTTPConnection('192.168.0.179', 8080, timeout=10)
     headers = {'Content-type': 'application/json'}
     while True:
         ahorita = datetime.now()
         datos = {"ahora": str(ahorita),"ip":ip.getIp()}
         json_datos = json.dumps(datos)
         connection.request("PUT", "/update_last_time",json_datos)
         connection.close()
         time.sleep(2)
         if p==0:
             self.recibir()
         p=p+1
Esempio n. 5
0
def run(version):
    assert (version == 4 or version == 6)
    dnsType = 'AAAA' if version == 6 else 'A'
    domains = CONFIG[f'ipv{version}']
    if not domains:
        APP.debug(f'未配置IPv{version},不需要更新。')
        return
    try:
        APP.debug('*' * 40 + f'IPv{version}' + '*' * 40)
        newIP = getIp(version)
        APP.debug(f'解析IPv{version}结果为:{newIP}')
        changedDomains = []
        for subDomain in domains:
            oldIp = getOldIP(version, subDomain)
            if newIP != oldIp or CONFIG['force']:
                APP.info(f'域名{subDomain}的IPv{version}已发生改变,上次地址为{oldIp}')

                result = refreshRecord(subDomain, newIP, version)
                status = result['status']
                if status['code'] != '1':
                    raise RuntimeError('{}-{}'.format(status['code'],
                                                      status['message']))

                APP.info(f'域名{subDomain}的{dnsType}纪录已经更新为{newIP}')
                changedDomains.append(subDomain)
            else:
                APP.debug(f'域名{subDomain}的{dnsType}纪录未发生改变')
        if not CONFIG['dry']:
            saveIP(version, newIP, domains)
        if changedDomains:
            notify({
                'version': version,
                'dnsType': dnsType,
                'ip': newIP,
                'domains': ','.join(changedDomains)
            })
    except Exception as ex:
        APP.error(f'!!!运行失败,原因:{ex}')
        notify({
            'version': version,
            'dnsType': dnsType,
            'domains': ','.join(domains),
            'error': ex
        })

    if CONFIG['dry']:
        print('\n\n' + '!' * 20 + f'-这是在dry模式下运行,实际IPv{version}域名未作更新-' +
              '!' * 20)
Esempio n. 6
0
 def register(self, nombre):
     return self.conv_json({"reason": "register", "ip": ip.getIp(), "user": nombre})
Esempio n. 7
0
 def verify(self):
     return self.conv_json({"reason": "verify", "ip": ip.getIp()})