- Timestamp:
- Aug 25, 2011, 1:08:02 PM (13 years ago)
- Location:
- src/django_gheat/gheat
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/gheat/management/commands/import_kismet.py
r9561 r9562 36 36 netxml_doc = etree.parse(open_file(netxml_file)) 37 37 38 counters = { 'ap_added' : 0, 'ap_total' : 0, 'ap_failed' : 0, 'ap_ignored' : 0} 38 counters = { 'ap_added' : 0, 'ap_total' : 0, 'ap_failed' : 0, 'ap_ignored' : 0, 39 'client_added' : 0, 'client_total' : 0, 'client_failed' : 0, 'client_ignored' : 0} 39 40 40 41 # Prepare new accespoints and measurements … … 43 44 # Temponary holders 44 45 ap_pool = {} 46 client_pool = {} 45 47 46 48 # Create all accesspoints and for caching validation purposes store them 47 49 # locally as well 48 50 for wnetwork in wnetworks: 49 counters['ap_total'] += 150 51 bssid = wnetwork.find('BSSID').text 51 # Only store access points52 52 ap_type = wnetwork.attrib['type'] 53 # Only access points and clients (for ignore listings) 53 54 if ap_type in ['infrastructure', 'data']: 55 counters['ap_total'] += 1 54 56 encryption = (wnetwork.find('SSID/encryption') != None) 55 57 ssid_node = wnetwork.find('SSID/essid[@cloaked="false"]') … … 58 60 ap_pool[bssid] = (ssid, encryption) 59 61 elif ap_type in ['probe', 'ad-hoc']: 60 counters[' ap_ignored'] += 161 c ontinue62 counters['client_total'] += 1 63 client_pool[bssid] = True 62 64 else: 63 65 logger.error('Unknown type %s - %s',bssid, wnetwork.attrib['type']) 64 66 65 67 66 # Determine which entries we needto add68 # Determine which Accespoints to add 67 69 bssid_list_present = Accespoint.objects.filter(mac__in=ap_pool.keys()).values_list('mac', flat=True) 68 70 bssid_list_insert = set(ap_pool.keys()) - set(bssid_list_present) … … 77 79 sql_values.append(item) 78 80 counters['ap_added'] = bulk_sql('gheat_accespoint (`mac`, `ssid`, `encryptie`)',sql_values) 81 82 # Determine which Wireless to add 83 bssid_list_present = WirelessClient.objects.filter(mac__in=client_pool.keys()).values_list('mac', flat=True) 84 bssid_list_insert = set(client_pool.keys()) - set(bssid_list_present) 85 86 # Create a bulk import list and import 87 if bssid_list_insert: 88 sql_values = [] 89 for bssid in bssid_list_insert: 90 sql_values.append("('%s')" % bssid) 91 counters['client_added'] = bulk_sql('gheat_wirelessclient (`mac`)',sql_values) 79 92 80 93 return counters … … 118 131 meting_pool[key].append(signaal) 119 132 133 bssid_list = [x[0] for x in meting_pool.keys()] 120 134 # Build mapping for meting import 121 135 mac2id = {} 122 for mac,id in Accespoint.objects.filter(mac__in= meting_pool.keys()).values_list('mac','id'):136 for mac,id in Accespoint.objects.filter(mac__in=bssid_list).values_list('mac','id'): 123 137 mac2id[mac] = int(id) 138 139 clients = {} 140 for mac in WirelessClient.objects.filter(mac__in=bssid_list).values_list('mac',flat=True): 141 clients[mac] = True 124 142 125 143 sql_values = [] 126 144 for (bssid,lat,lon),signals in meting_pool.iteritems(): 127 if not mac2id.has_key(bssid): 145 if clients.has_key(bssid): 146 counters['meting_ignored'] += len(signals) 147 elif not mac2id.has_key(bssid): 128 148 counters['meting_failed'] += len(signals) 129 149 bssid_failed[bssid] += len(signals) 130 continue131 item = str((int(meetrondje.id),mac2id[bssid],float(lat),float(lon),max(signaal)))132 sql_values.append(item)150 else: 151 item = str((int(meetrondje.id),mac2id[bssid],float(lat),float(lon),max(signals))) 152 sql_values.append(item) 133 153 134 154 for bssid,count in sorted(bssid_failed.items(), … … 168 188 counters = import_kismet_netxml(xml_file) 169 189 logger.info("summary accespoints: total:%(ap_total)-6s added:%(ap_added)-6s failed:%(ap_failed)-6s ignored:%(ap_ignored)-6s" % counters) 190 logger.info("summary client : total:%(client_total)-6s added:%(client_added)-6s failed:%(client_failed)-6s ignored:%(client_ignored)-6s" % counters) 170 191 elif 'gpsxml' in xml_file: 171 192 if options['datum'] == None: … … 192 213 if not created: 193 214 logger.error("Meetrondje '%s' already imported" % mr) 194 sys.exit(1)215 continue 195 216 counters = import_kismet_gpsxml(xml_file, mr) 196 217 logger.info("summary metingen : total:%(meting_total)-6s added:%(meting_added)-6s failed:%(meting_failed)-6s ignored:%(meting_ignored)-6s" % counters) -
src/django_gheat/gheat/models.py
r9552 r9562 52 52 return hashlib.md5(source).hexdigest() 53 53 54 class WirelessClient(models.Model): 55 mac = models.CharField(max_length=17, unique=True) 56 def __unicode__(self): 57 return self.mac 54 58 55 59 class Accespoint(models.Model): … … 57 61 ssid = models.CharField(max_length=64) 58 62 encryptie = models.BooleanField() 63 class Meta: 64 unique_together = ('mac', 'ssid') 59 65 def __unicode__(self): 60 66 return "%s - %s" % (self.mac, self.ssid)
Note:
See TracChangeset
for help on using the changeset viewer.