def test_oui_constructor(): oui = OUI(524336) assert str(oui) == '08-00-30' assert oui == OUI('08-00-30') assert oui.registration(0).address == [ '2380 N. ROSE AVENUE', 'OXNARD CA 93010', 'US' ] assert oui.registration(0).org == 'NETWORK RESEARCH CORPORATION' assert oui.registration(0).oui == '08-00-30' assert oui.registration(1).address == [ 'GPO BOX 2476V', 'MELBOURNE VIC 3001', 'AU', ] assert oui.registration(1).org == 'ROYAL MELBOURNE INST OF TECH' assert oui.registration(1).oui == '08-00-30' assert oui.registration(2).address == [ 'CH-1211 GENEVE 23', 'SUISSE/SWITZ', 'CH' ] assert oui.registration(2).org == 'CERN' assert oui.registration(2).oui == '08-00-30' assert oui.reg_count == 3
def test_eui_information_subset_for_entry_with_incorrect_encoding(): filename = "sample_incorrect_encoded_oui.txt" index, registry = get_sample_oui_index_and_registry(filename) oui = OUI(9097, index, registry) address = [ 'Oriental Electronics Bldg., #2, Chuangye Road' '\xc3\u201a\xc2\xa3\xc3\u201a\xc2\xac' 'Shangdi Information ' 'Industry Base,', 'Haidian District, Beijing, P.R.China', 'Beijing 100085', 'CHINA' ] assert oui.registration().address == address
def display(self): shown = set() res=["typ AP SSID* MAC vendor" " channels cnt max min avg" " sp rssi flg attempts"] # the header is just one long string!!! for k, v in sorted(self.peers.items(),key=lambda (k,v): len(v.get('peers',[])), reverse=True): if v['type']!='ap': continue try: vendor = OUI(k[:8].replace(':','-')).registration().org[:20] except: vendor = '' if len(vendor)>20: vendor = "%s..." % vendor[:20] flags=''.join([flagmap.get(k[:8], ''), flagmap.get(k[:13], '')]) res.append("AP %-30s %s %-23s %s %-3s" % (', '.join(v.get('ssids',[])), k, vendor, self.rfstats(v['seen']), flags)) for client in sorted(v.get('peers',[]), lambda _,v1: len(self.peers[v1].get('ssids',[])) ,reverse=True): res.append(" %-30s %s" % (', '.join(v.get('ssids',[])), self.print_client(client, self.peers[client]))) shown.add(client) for k, v in self.peers.items(): if v['type']!='client' or k in shown: continue res.append("CL %s %s" % (' '*30, self.print_client(k,v))) for k, v in self.peers.items(): if v['type']!='unknown': continue res.append("NA %s <-> %s" % (k, v.get('peers'))) return '\n'.join(res)
def print_client(self, k, v): if v['type']!='client': return '[wtf] type is not client %s %s' % (k, v) try: vendor = OUI(k[:8].replace(':','-')).registration().org except: vendor = '' if len(vendor)>20: vendor = "%s..." % vendor[:20] flags=''.join([flagmap.get(k[:8], ''), flagmap36.get(k[:13], '')]) return "%s %-23s %s %-3s %s" % (k, vendor, self.rfstats(v['seen']), flags, ', '.join(v.get('ssids',[])))
def test_eui64(): eui = EUI('00-1B-77-FF-FE-49-54-FD') assert eui == EUI('00-1B-77-FF-FE-49-54-FD') assert eui.oui == OUI('00-1B-77') assert eui.ei == 'FF-FE-49-54-FD' assert eui.eui64() == EUI('00-1B-77-FF-FE-49-54-FD')
def test_oui_hash(): oui0 = OUI(0) oui1 = OUI(1) oui_dict = {oui0: None, oui1: None} assert list(oui_dict.keys()) == [OUI(0), OUI(1)]