Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cloud4rpi-wol
# ...
def wake_pc(value):
if value:
return wol.wake()
def ping_pc(value):
return wol.ping()
def main():
variables = {
'PC IP': {
'type': 'string',
'value': False,
'bind': ping_pc,
},
'PC WoL': {
'type': 'bool',
'value': False,
'bind': wake_pc,
}
}
# ...
import subprocess
import wakeonlan
wol_target_mac = 'FF-FF-FF-FF-FF-FF'
wol_target_host = 'himura-pc'
def ping():
try:
out = subprocess.check_output(['ping', '-W', '2', '-c', '1', wol_target_host])
if '1 received' in out:
return out.split('bytes from ', 1)[1].split(':', 1)[0] # Extracts the IP
return 'Offline'
except subprocess.CalledProcessError:
return 'Offline'
def wake():
for _ in range(3):
wakeonlan.send_magic_packet(wol_target_mac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.