Last active
April 1, 2018 09:19
-
-
Save Himura2la/9dfeba38ea5e9ddf87c69d859d56cafa to your computer and use it in GitHub Desktop.
cloud4rpi-wol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
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, | |
} | |
} | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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