source: src/django_gheat/gheat/management/commands/kismet.py@ 9631

Last change on this file since 9631 was 9629, checked in by rick, 13 years ago

Logging OK, but no setting of levels inside modules

  • Property svn:executable set to *
File size: 2.3 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Rick van der Zwet <info@rickvanderzwet.nl>
5#
6from lxml import etree
7import logging
8
9from collections import defaultdict
10
11logger = logging.getLogger(__name__)
12
13def process_netxml(fh,counters):
14 netxml_doc = etree.parse(fh)
15
16 # Prepare new accespoints and measurements
17 wnetworks = netxml_doc.findall('wireless-network')
18
19 # Temponary holders
20 ap_pool = {}
21 client_pool = {}
22
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
27 ap_type = wnetwork.attrib['type']
28 # Only access points and clients (for ignore listings)
29 if ap_type in ['infrastructure', 'data']:
30 counters['ap_total'] += 1
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']:
37 counters['client_total'] += 1
38 client_pool[bssid] = True
39 else:
40 logger.error('Unknown type %s - %s',bssid, wnetwork.attrib['type'])
41
42 return (counters, ap_pool, None, None)
43
44
45
46def process_gpsxml(fh,counters):
47 gpsxml_doc = etree.parse(fh)
48
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
57 for point in points:
58 counters['meting_total'] += 1
59 #XXX: This needs to be either the 'bssid' or the 'source',
60 #XXX: accesspoint from or too data.
61 bssid = point.attrib['bssid']
62 # XXX: Filter this in the beginning with XPath, but etree does not support
63 # that (yet).
64 if bssid in ['GP:SD:TR:AC:KL:OG','00:00:00:00:00:00']:
65 counters['meting_ignored'] =+ 1
66 continue
67 # XXX: Signal need properly be a relation of signal_dbm and noice_dbm
68 try:
69 level = point.attrib['signal_dbm']
70 except KeyError:
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)
78 return (counters, None, None, meting_pool)
Note: See TracBrowser for help on using the repository browser.