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

Last change on this file since 9627 was 9623, checked in by rick, 14 years ago

Merge and migrate all files into common files to get rid of all duplicate codes.

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