-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwardrive.py
More file actions
99 lines (91 loc) · 5.25 KB
/
Copy pathwardrive.py
File metadata and controls
99 lines (91 loc) · 5.25 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
import RPi.GPIO as GPIO
import os
import subprocess
import gps
import time
from ConfigParser import SafeConfigParser
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(04, GPIO.OUT)#LED1 KISMET
GPIO.setup(17, GPIO.OUT)#LED2 GPSD running
GPIO.setup(9, GPIO.OUT)#LED5 Upload in progress.
GPIO.setup(26, GPIO.IN)#Data upload switch,momentarily toggle.
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)#Power button,triggers on falling flank.
GPIO.output(04, True)#Makes sure all LED's are at the same state initially (off):
GPIO.output(17, True)
GPIO.output(22, True)
GPIO.output(9, True)
GPIO.output(10, True)
configFile = SafeConfigParser()#Sets up a parser for the Config File
configFile.read('wardrive.config')#Reads the wardrive.config file.
##The following while loop is the main code execution
while True:
executeKismet()
executeGPS()
while True:
if (GPIO.input(26)): #If upload button is pressed
uploadButton()
if (GPIO.input(7)): #If power button is pressed
time.sleep(0.05)
os.system("shutdown -h now")
def executeKismet():
kismet = subprocess.Popen(['ps -ef | grep kismet'],
stdout=subprocess.PIPE, shell=True) #Assigns the output from the grep to the kismet variable
(output, error) = kismet.communicate()
if 'kismet_server' in output:
GPIO.output(04, False) #Turn on KISMET LED
else:
GPIO.output(04, True) #Turn off KISMET LED
def executeGPS():
gps = subprocess.Popen(['ps -ef | grep gpsd'],
stdout=subprocess.PIPE, shell=True)#Assigns the output from the grepto the gps variable
(output, error) = gps.communicate()
if 'gpsd' in output:
GPIO.output(17, False) #Turn on GPSD LED
else:
GPIO.output(17, True) #Turn off GPSD LED
def uploadButton():
time.sleep(0.05)
os.system("killall kismet_server")
time.sleep(3)# added so kismet has the time to die.
os.system("iwconfig wlan0 essid " + configFile.get('Home Wireless Setup', 'ssid') + " key " + configFile.get('Home Wireless Setup', 'network_key'))#Connects to your home Wireless
time.sleep(10)# added so wlan0 has time to autenticate and assosiate with the wlan node
if connectivityTest(): #Checks for internet connectivity. (Mainly connectivity to wigle.net)
print "This executes when there is connectivity to wigle.net"
GPIO.output(9, False)#Turns on upload LED
wigleUsername = configFile.get('Wigle.net Setup', 'wigleUsername')
wiglePassword = configFile.get('Wigle.net Setup', 'wiglePassword')
#This grabs the authentication cookie used when uploading a file (its login into wigle.net). The cookie is stored in the current directory in a file called wigleCookie.txt
loginAndCookieGrab = subprocess.Popen("curl -c wigleCookie.txt -d \"credential_0=" + wigleUsername + "&credential_1=" + wiglePassword +" https://wigle.net/gps/gps/main/login/", shell=True, stdout=PIPE, stderr=PIPE)
loginAndCookieGrabOut, loginAndCookieGrabErr = loginAndCookieGrab.communicate()
#This uploads the output file from kismet to wigle.net. It used the cookie retrived from before during the upload process so it is authenticated.
upload = subprocess.Popen("curl -b wigleCookie.txt -F \"stumblefile=@/var/log/kismet -d \"Send=Send&observer=" + wigleUsername + " https://wigle.net/gps/gps/main/postfile", shell=True, stdout=PIPE, stderr=PIPE)
uploadOut, uploadErr = upload.communicate()
command = os.system('ifconfig wlan0 down')#disables the wireless interface, i think thats a "ugly" way to disconnect.
command = os.system('dhclient -r wlan0')#Releases the DHCP IP.
command = os.system('ifconfig wlan0 up')#turns the interface back on, so kismet can access it.
time.sleep(1.5)#pause so wlan0 has time to come up.
#command = os.system('rm -v /path/to/kismet/logfiles/*.cap') grabs path from config file, and deletes all .cap files in it. The -v option displays info about the deletion process.
command = os.system('kismet_server -s --daemonize')#restarts kismet_server to resume scanning.
#Then deleting the uploaded file from /kismet-logs, disconnects from the wlan node and resumes (restarts kismet?)
else:
print "This executes when there is no connectivity to wigle.net"#Line to be removed (Used for Dubugging)
GPIO.output(9, True)#Turns off upload LED
def connectivityTest():
#Pings wigle.net
thePing = subprocess.Popen('ping -c 5 wigle.net', shell=True, stdout=PIPE, stderr=PIPE)
pingOut, pingErr = thePing.communicate()
if len(pingErr) > 0: #If the ping fails ping 8.8.8.8
thePing = subprocess.Popen('ping -c 5 8.8.8.8', shell=True, stdout=PIPE, stderr=PIPE)
pingOut, pingErr = thePing.communicate()
print 1
if len(pingErr) > 0:#If pinging 8.8.8.8 fails display there is no internet connection
print "There is no internet connectivity"#Line to be removed (Used for Dubugging)
return False
else:#If pinging 8.8.8.8 succeeds, display there is no DHCP service.
print "There is no DHCP server"#Line to be removed (Used for Dubugging)
return False
else:
print "There is connectivity"#Line to be removed (Used for Debugging)
return True