source: src/django_gheat/gheat/dataimport/kismet.py@ 9819

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

Correct annoying typo in naming of the acces*s* point.

  • Property svn:executable set to *
File size: 2.5 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 try:
15 netxml_doc = etree.parse(fh)
16 except etree.XMLSyntaxError, e:
17 raise IOError(e)
18
19 # Prepare new accesspoints and measurements
20 wnetworks = netxml_doc.findall('wireless-network')
21
22 # Temponary holders
23 ap_pool = {}
24 client_pool = {}
25
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
30 ap_type = wnetwork.attrib['type']
31 # Only access points and clients (for ignore listings)
32 if ap_type in ['infrastructure', 'data']:
33 counters['ap_total'] += 1
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']:
40 counters['client_total'] += 1
41 client_pool[bssid] = True
42 else:
43 logger.error('Unknown type %s - %s',bssid, wnetwork.attrib['type'])
44
45 return (counters, ap_pool, None, None)
46
47
48
49def process_gpsxml(fh,counters):
50 try:
51 gpsxml_doc = etree.parse(fh)
52 except etree.XMLSyntaxError, e:
53 raise IOError(e)
54
55 bssid_failed = defaultdict(int)
56
57 # Prepare new accesspoints and measurements
58 points = gpsxml_doc.findall('gps-point')
59
60 # Temponary holders
61 meting_pool = defaultdict(list)
62
63 for point in points:
64 counters['meting_total'] += 1
65 #XXX: This needs to be either the 'bssid' or the 'source',
66 #XXX: accesspoint from or too data.
67 bssid = point.attrib['bssid']
68 # XXX: Filter this in the beginning with XPath, but etree does not support
69 # that (yet).
70 if bssid in ['GP:SD:TR:AC:KL:OG','00:00:00:00:00:00']:
71 counters['meting_ignored'] =+ 1
72 continue
73 # XXX: Signal need properly be a relation of signal_dbm and noice_dbm
74 try:
75 level = point.attrib['signal_dbm']
76 except KeyError:
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)
84 return (counters, None, None, meting_pool)
Note: See TracBrowser for help on using the repository browser.