First implementation for detected wifi cards database
[wifihood] / wifisniffer / wificards.py
1
2 discovered = {}
3
4
5 def add_card ( mac , radio_hdr ) :
6     if not discovered.has_key( mac ) :
7         discovered[ mac ] = card( mac , radio_hdr['CHANNEL'] )
8         print "INFO : adding node %3d , %s" % ( len(discovered) , mac )
9
10
11 def add_full_card ( mac , tipo , subtype , radio_hdr ) :
12     if not discovered.has_key( mac ) :
13         discovered[ mac ] = card( mac , radio_hdr['CHANNEL'] , tipo )
14         print "INFO : adding node %3d , %s" % ( len(discovered) , mac )
15     elif not discovered[ mac ].tipo :
16         discovered[ mac ].tipo = tipo
17     elif discovered[ mac ].tipo != tipo :
18         print "WARNING : AP/STA mismatch on %s for %s" % ( subtype , mac )
19
20
21 class card :
22
23     def __init__ ( self , mac , channel=None , tipo=None ) :
24         self.mac = mac
25         self.fresh = True
26         self.tipo = tipo
27         self.channel = []
28         self.rssi = [ 0 , 0 , 0 , 0 , 0 ]
29         self.sta = []
30         if channel :
31             self.channel.append( "%s" % channel )
32
33     def add_rssi ( self , radio_hdr ) :
34         signal = int(radio_hdr['DBM_ANTSIGNAL'])
35         noise  = int(radio_hdr['DBM_ANTNOISE'])
36         self.rssi[0] = self.rssi[0] + 1
37         self.rssi[1] = self.rssi[1] + signal
38         self.rssi[2] = self.rssi[2] + signal**2
39         self.rssi[3] = self.rssi[3] + noise
40         self.rssi[4] = self.rssi[4] + noise**2
41
42     def from_string ( self , str_list ) :
43         self.tipo = str_list.pop(0)
44         self.channel.extend( str_list.pop(0).split(",") )
45         self.rssi = map( int , str_list.pop(0).split(",") )
46         if str_list :
47             self.sta.extend( str_list.pop(0).split(",") )
48         self.fresh = False
49
50     def add_sta ( self , mac ) :
51         if mac not in self.sta :
52             self.sta.append( mac )
53
54     def __str__ ( self ) :
55         rssi_str = ",".join( map( str , self.rssi ) )
56         return "%s %s %s %s %s" % ( self.mac , self.tipo , ",".join( self.channel ) , rssi_str , ",".join( self.sta ) )
57