def on_message(client, userdata, msg): print("主题:" + msg.topic + " 消息:" + str(msg.payload)) if (msg.payload == b'wake on lan'): wol.send_magic_packet('2CF05D0851D8') if (msg.payload == b'get ip'): print(whatsmyip.getip()) client.publish("/ip", whatsmyip.getip(), qos=1, retain=False) #对于ping订阅发送当前获取的延迟时间
LATCH_APP_ID = (linea[0]).strip() LATCH_SECRET = (linea[1]).strip() latchuserid = (linea[2]).strip() archivoparear.close() except IOError: syslog.syslog(syslog.LOG_ERR, "El archivo parear.data no existe o no tiene los permisos adecuados.") break try: latcheo = latch.Latch(LATCH_APP_ID, LATCH_SECRET) response = latcheo.status(latchuserid) if response.get_data()['operations'][LATCH_APP_ID]['status'] == 'on': #SI EL SISTEMA LATCH NOS DICE QUE ESTA ESTA EN ON, CARGA EL FICHERO DE LAS MAC-ADDRESS DE LOS EQUIPOS A ENCENDER try: archivoequipos=open('/usr/local/src/latchwake/equipos.data','r') linea=archivoequipos.readline() while linea!="": #ENCIENDE LOS EQUIPOS wol.send_magic_packet(linea.strip()) linea=archivoequipos.readline() archivoequipos.close() except IOError: syslog.syslog(syslog.LOG_ERR, "El archivo equipos.data no existe o no tiene los permisos adecuados.") break else: pass except: syslog.syslog(syslog.LOG_ERR, "No se ha podido conectar con el servidor de Latch.") time.sleep(30)
def boot(computer): if computer not in computer_list: abort(404) wol.send_magic_packet(computer_list[computer]) return 'Booting...'
def wake_on_lan(mac_addr): send_magic_packet(mac_addr)