Changeset 9562


Ignore:
Timestamp:
Aug 25, 2011, 1:08:02 PM (13 years ago)
Author:
rick
Message:

Start importing clients as well, to generate an ignore list...

Location:
src/django_gheat/gheat
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/management/commands/import_kismet.py

    r9561 r9562  
    3636  netxml_doc = etree.parse(open_file(netxml_file))
    3737
    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}
    3940
    4041  # Prepare new accespoints and measurements
     
    4344  # Temponary holders
    4445  ap_pool = {}
     46  client_pool = {}
    4547
    4648  # Create all accesspoints and for caching validation purposes store them
    4749  # locally as well
    4850  for wnetwork in wnetworks:
    49     counters['ap_total'] += 1
    5051    bssid = wnetwork.find('BSSID').text
    51     # Only store access points
    5252    ap_type = wnetwork.attrib['type']
     53    # Only access points and clients (for ignore listings)
    5354    if ap_type in ['infrastructure', 'data']:
     55      counters['ap_total'] += 1
    5456      encryption = (wnetwork.find('SSID/encryption') != None)
    5557      ssid_node = wnetwork.find('SSID/essid[@cloaked="false"]')
     
    5860      ap_pool[bssid] = (ssid, encryption)
    5961    elif ap_type in ['probe', 'ad-hoc']:
    60       counters['ap_ignored'] += 1
    61       continue
     62      counters['client_total'] += 1
     63      client_pool[bssid] = True
    6264    else:
    6365      logger.error('Unknown type %s - %s',bssid, wnetwork.attrib['type'])
    6466
    6567
    66   # Determine which entries we need to add
     68  # Determine which Accespoints to add
    6769  bssid_list_present = Accespoint.objects.filter(mac__in=ap_pool.keys()).values_list('mac', flat=True)
    6870  bssid_list_insert = set(ap_pool.keys()) - set(bssid_list_present)
     
    7779      sql_values.append(item)
    7880    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)
    7992
    8093  return counters
     
    118131    meting_pool[key].append(signaal)
    119132
     133  bssid_list = [x[0] for x in meting_pool.keys()]
    120134  # Build mapping for meting import
    121135  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'):
    123137    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
    124142
    125143  sql_values = []
    126144  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):
    128148      counters['meting_failed'] += len(signals)
    129149      bssid_failed[bssid] += len(signals)
    130       continue
    131     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)
    133153
    134154  for bssid,count in sorted(bssid_failed.items(),
     
    168188        counters = import_kismet_netxml(xml_file)
    169189        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)
    170191      elif 'gpsxml' in xml_file:
    171192        if options['datum'] == None:
     
    192213        if not created:
    193214          logger.error("Meetrondje '%s' already imported" % mr)
    194           sys.exit(1)
     215          continue
    195216        counters = import_kismet_gpsxml(xml_file, mr)
    196217        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  
    5252    return hashlib.md5(source).hexdigest()
    5353
     54class WirelessClient(models.Model):
     55  mac = models.CharField(max_length=17, unique=True)
     56  def __unicode__(self):
     57    return self.mac
    5458
    5559class Accespoint(models.Model):
     
    5761  ssid = models.CharField(max_length=64)
    5862  encryptie = models.BooleanField()
     63  class Meta:
     64    unique_together = ('mac', 'ssid')
    5965  def __unicode__(self):
    6066    return "%s - %s" % (self.mac, self.ssid)
Note: See TracChangeset for help on using the changeset viewer.