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