Wifi Scaning: HOMEWORK #3 Report
Wifi Scaning: HOMEWORK #3 Report
WIFI SCANING
Abstact:
In this homework, we are going to implement an android Wifi scanner and then go around the some part of the town to build a map of the wifi AP in Clemson. The steps are as follows: Use the Python for android to write a wifi scanner program that collects wifi information plus GPS coordinates. Going through Clemson city, collect data, plot a map and determine the distribution of WEP/WPA/Open wifi in town. Run the program on an Android phone and plot an interactive map of the data on Google Maps. This report will be divided into 4 parts: 1. Introduction to Python for Andriod 2. Implementation of the program 3. Data collection and result map
4.
Data Analysis
1.
Introduction
In this project, we will implement a wifi scanner which can run on an Android platform phone set and collect AP data. We are using sl4a and Python for Android app which allows user to run python scripts on the Android platform. The Python for Android library contains a lot of API to allow user to control the phone without any programming knowledge of Android SDK.
We will take the phone set which is running our program to get through Clemson downtown area and collect AP data and corresponding GPS data, put them into a KML file. And then we upload the KML file on to Google map and generate an AP data map of Clemson area.
The phone model : Google Nexus one (HTC) The Android version : MIUI 1.11.4
2.
Implementation
import android import sys import time import os droid = android.Android() droid.startLocating()
# Start scanning access_points = {} try : startTime = 0 #backup data every 5 mins cyclePeriod = 300 while True : if not droid.wifiStartScan()[1] : time.sleep(1) continue location = droid.readLocation().result
# Extract the data from the array for ap in scan : if not access_points.has_key(ap['bssid']) :
print int(time.time()), 'new ap', ap['bssid'], ap['ssid'] access_points[ap['bssid']] = {} access_points[ap['bssid']]['ssid'] = ap['ssid'] access_points[ap['bssid']]['level'] = ap['level'] access_points[ap['bssid']]['capabilities'] = ap['capabilities'] access_points[ap['bssid']]['longitude'] = location['gps'] ['longitude'] access_points[ap['bssid']]['latitude'] = location['gps'] ['latitude'] access_points[ap['bssid']]['time'] = int(time.time()) elif ap['level'] > access_points[ap['bssid']]['level'] : print int(time.time()), 'location update', ap['level'], ap['ssid'], ap['bssid'] access_points[ap['bssid']]['level'] = ap['level'] access_points[ap['bssid']]['latitude'] = location['gps'] ['latitude'] access_points[ap['bssid']]['longitude'] = location['gps'] ['longitude'] access_points[ap['bssid']]['time'] = int(time.time()) #time.sleep(0.1) startTime += 1 if startTime >= cyclePeriod: #backup = open('/sdcard/sl4a/backup.kml', 'w')
backup = open('/sdcard/sl4a/scan-'+str(int(time.time())) +'.kml', 'w') backup.write('<?xml version="1.0" encoding="UTF-8"? >\n') backup.write('<kml xmlns="http://www.opengis.net/kml/2.2">\n') backup.write('<Document>\n') for ap in access_points : backup.write(' backup.write(' access_points[ap]['ssid']) backup.write(' <Placemark>\n') <name>%s</name>\n' % <Point>\n')
</Placemark>\n')
# When catching up keyboard interrupt, save all the data into KML #file. #
except KeyboardInterrupt : fh = open('/sdcard/sl4a/scan-'+str(int(time.time()))+'.txt', 'w') kmlfile = open('/sdcard/sl4a/scan-'+str(int(time.time()))+'.kml', 'w') kmlfile.write('<?xml version="1.0" encoding="UTF-8"?>\n') kmlfile.write('<kml xmlns="http://www.opengis.net/kml/2.2">\n') kmlfile.write('<Document>\n') for ap in access_points : fh.write(ap + '|' + access_points[ap]['ssid'] + '|') fh.write(str(access_points[ap]['level']) + '|') fh.write(access_points[ap]['capabilities'] + '|') fh.write(str(access_points[ap]['longitude']) + '|') fh.write(str(access_points[ap]['latitude']) + '|') fh.write(str(access_points[ap]['time']) + '\n') kmlfile.write(' kmlfile.write(' ['ssid']) kmlfile.write(' <Placemark>\n') <name>%s</name>\n' % access_points[ap] <Point>\n')
kmlfile.write('</Document>\n') kmlfile.write('</kml>\n')
fh.close() kmlfile.close()
Data Analysis
Total WEP WPA2 WPA 260 54 127 79 20.77% 48.85% 30.38% (unsafe)