-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpc.py
47 lines (37 loc) · 974 Bytes
/
pc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import wakeonlan
import subprocess
import time
from icmplib import ping
from h import PCARP, SHOST, PCHOST, PCSC
class Pc:
def __init__(self):
self.arp = PCARP
self.interface = SHOST
def __del__(self):
pass
close = __del__
def isOn(self):
try:
p = ping(PCHOST, count=1, timeout=2)
except:
return False
if p.packets_received == 0:
return False
return True
def on(self):
wakeonlan.send_magic_packet(self.arp, interface=self.interface)
return True
def off(self):
command = PCSC.split()
call = subprocess.run(command, stdout=subprocess.PIPE, encoding='UTF8')
return True if call.returncode == 0 else False
if __name__ == "__main__":
p = Pc()
print(p.isOn())
print("starting ...")
print(p.on())
time.sleep(30)
print(p.isOn())
print("stopping ...")
print(p.off())
p.close()