forked from jamiehoward/pydetect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.py
executable file
·71 lines (63 loc) · 1.57 KB
/
device.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import time
import sys
from pushover import init, Client
init("<token>")
client = Client("<user-key>").send_message("Hello!", title="Hello")
os.system('clear')
deviceIP = 10.0.0.201 #raw_input("Enter the IP address to listen for: ")
cacheFolder = "cache/"
cacheFileName = time.time()
filePath = cacheFolder + str(cacheFileName)
def checkForDevice():
# See if the device has connected to the network
systemCommand = "sudo arp-scan -l > " + filePath
os.system(systemCommand)
with open(filePath) as fileObj:
for line in fileObj.readlines():
if deviceIP in line:
success = True
break
else:
success = False
return success
def delayPrint(text):
print text
time.sleep(2)
def promptToRestart():
os.system('clear')
userChoice = raw_input("restart or exit? ")
if (userChoice == 'restart'):
connectionDaemon()
elif(userChoice == 'exit'):
exit()
else:
delayPrint('Invalid selection!')
promptToRestart()
def connectionActions():
# Do this stuff when connected
import smtplib
try:
server = smtplib.SMTP( "smtp.gmail.com", 587 )
server.starttls()
server.login( '<email address>', '<email pass>' )
server.sendmail( '<from>', '<to>', '<message>' )
except:
delayPrint('Connection failed')
connectionDaemon()
delayPrint('SMS sent!')
promptToRestart()
pass
def connectionDaemon():
i = 0
while (i == 0):
# Keep on searching, yo! (Indefinitely)
connected = checkForDevice()
if (connected == True):
os.system('clear')
print "Device is ONLINE"
connectionActions()
else:
os.system('clear')
print "Device is OFFLINE"
connectionDaemon()