Skip to content

Instantly share code, notes, and snippets.

@Himura2la
Last active April 1, 2018 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Himura2la/9dfeba38ea5e9ddf87c69d859d56cafa to your computer and use it in GitHub Desktop.
Save Himura2la/9dfeba38ea5e9ddf87c69d859d56cafa to your computer and use it in GitHub Desktop.
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