import socket import pprint import struct import sys # Kommando. um den Fernseher anzubekommen: # echo 'on 0' | cec-client -s from uuid import getnode as get_mac # seems to be the easiest way to get the "outer" IP address. All other tricks failed as the host name is hardcoded against 127.0.0.1 in /etc/hosts on Kodi :-( s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) UDP_IP=s.getsockname()[0] s.close() UDP_PORT = 9 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) mac = get_mac() mac=''.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2)) # create magic packet magic_packet = ''.join(['FF' * 6, mac * 16]) send_data = '' for i in range(0, len(magic_packet), 2): send_data = ''.join([send_data, struct.pack('B', int(magic_packet[i: i + 2], 16))]) result=0 while result==0: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes #print ("received message:") #pprint.pprint(data) #print("--------") #pprint.pprint(send_data) if data==send_data: print("Magic Paket identified") result=1 sys.exit(result)