[9078] | 1 | #!/usr/bin/env python
|
---|
[9560] | 2 | # -*- coding: utf-8 -*-
|
---|
[9084] | 3 | #
|
---|
[9560] | 4 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
| 5 | #
|
---|
[9078] | 6 | from lxml import etree
|
---|
[9552] | 7 | import logging
|
---|
[9078] | 8 |
|
---|
[9560] | 9 | from collections import defaultdict
|
---|
[9552] | 10 |
|
---|
[9560] | 11 | logger = logging.getLogger(__name__)
|
---|
| 12 |
|
---|
[9623] | 13 | def process_netxml(fh,counters):
|
---|
[9668] | 14 | try:
|
---|
| 15 | netxml_doc = etree.parse(fh)
|
---|
| 16 | except etree.XMLSyntaxError, e:
|
---|
| 17 | raise IOError(e)
|
---|
[9560] | 18 |
|
---|
[9819] | 19 | # Prepare new accesspoints and measurements
|
---|
[9560] | 20 | wnetworks = netxml_doc.findall('wireless-network')
|
---|
[9078] | 21 |
|
---|
[9560] | 22 | # Temponary holders
|
---|
| 23 | ap_pool = {}
|
---|
[9562] | 24 | client_pool = {}
|
---|
[9560] | 25 |
|
---|
[9158] | 26 | # Create all accesspoints and for caching validation purposes store them
|
---|
| 27 | # locally as well
|
---|
| 28 | for wnetwork in wnetworks:
|
---|
| 29 | bssid = wnetwork.find('BSSID').text
|
---|
[9561] | 30 | ap_type = wnetwork.attrib['type']
|
---|
[9562] | 31 | # Only access points and clients (for ignore listings)
|
---|
[9561] | 32 | if ap_type in ['infrastructure', 'data']:
|
---|
[9562] | 33 | counters['ap_total'] += 1
|
---|
[9561] | 34 | encryption = (wnetwork.find('SSID/encryption') != None)
|
---|
| 35 | ssid_node = wnetwork.find('SSID/essid[@cloaked="false"]')
|
---|
| 36 | ssid = ssid_node.text if ssid_node != None else 'hidden'
|
---|
| 37 |
|
---|
| 38 | ap_pool[bssid] = (ssid, encryption)
|
---|
| 39 | elif ap_type in ['probe', 'ad-hoc']:
|
---|
[9562] | 40 | counters['client_total'] += 1
|
---|
| 41 | client_pool[bssid] = True
|
---|
[9561] | 42 | else:
|
---|
| 43 | logger.error('Unknown type %s - %s',bssid, wnetwork.attrib['type'])
|
---|
[9092] | 44 |
|
---|
[9623] | 45 | return (counters, ap_pool, None, None)
|
---|
[9158] | 46 |
|
---|
[9078] | 47 |
|
---|
[9560] | 48 |
|
---|
[9623] | 49 | def process_gpsxml(fh,counters):
|
---|
[9668] | 50 | try:
|
---|
| 51 | gpsxml_doc = etree.parse(fh)
|
---|
| 52 | except etree.XMLSyntaxError, e:
|
---|
| 53 | raise IOError(e)
|
---|
[9562] | 54 |
|
---|
[9561] | 55 | bssid_failed = defaultdict(int)
|
---|
| 56 |
|
---|
[9819] | 57 | # Prepare new accesspoints and measurements
|
---|
[9561] | 58 | points = gpsxml_doc.findall('gps-point')
|
---|
| 59 |
|
---|
| 60 | # Temponary holders
|
---|
| 61 | meting_pool = defaultdict(list)
|
---|
| 62 |
|
---|
[9158] | 63 | for point in points:
|
---|
[9561] | 64 | counters['meting_total'] += 1
|
---|
[9560] | 65 | #XXX: This needs to be either the 'bssid' or the 'source',
|
---|
| 66 | #XXX: accesspoint from or too data.
|
---|
[9168] | 67 | bssid = point.attrib['bssid']
|
---|
[9560] | 68 | # XXX: Filter this in the beginning with XPath, but etree does not support
|
---|
| 69 | # that (yet).
|
---|
[9168] | 70 | if bssid in ['GP:SD:TR:AC:KL:OG','00:00:00:00:00:00']:
|
---|
[9561] | 71 | counters['meting_ignored'] =+ 1
|
---|
[9158] | 72 | continue
|
---|
| 73 | # XXX: Signal need properly be a relation of signal_dbm and noice_dbm
|
---|
[9176] | 74 | try:
|
---|
[9560] | 75 | level = point.attrib['signal_dbm']
|
---|
[9176] | 76 | except KeyError:
|
---|
[9560] | 77 | logger.debug("Point '%s' does not have signal strengh" % point)
|
---|
| 78 | counters['meting_failed'] += 1
|
---|
| 79 | continue
|
---|
| 80 | # We store all values found, avg or max will be done later on
|
---|
| 81 | key = (bssid, point.attrib['lat'], point.attrib['lon'])
|
---|
| 82 | signaal=100 + int(level)
|
---|
| 83 | meting_pool[key].append(signaal)
|
---|
[9623] | 84 | return (counters, None, None, meting_pool)
|
---|