def test_encodedecodename(self): name = 'THISISAVERYLONGLONGNAME' encoded = nmb.encode_name(name, nmb.TYPE_SERVER, None) hexdump(encoded) decoded = nmb.decode_name(encoded) hexdump(bytearray(decoded[1], 'utf-8')) #self.assertEqual(nmb.TYPE_SERVER, decoded[0]) self.assertEqual(name[:15], decoded[1].strip())
def test_encodedecodename(self): name = 'THISISAVERYLONGLONGNAME' encoded = nmb.encode_name(name,nmb.TYPE_SERVER,None) hexdump(encoded) decoded = nmb.decode_name(encoded) hexdump(decoded[1]) #self.assertTrue(nmb.TYPE_SERVER==decoded[0]) self.assertTrue(name[:15]==decoded[1].strip())
def test_encodedecodename(self): name = 'THISISAVERYLONGLONGNAME' encoded = nmb.encode_name(name,nmb.TYPE_SERVER,None) hexdump(encoded) decoded = nmb.decode_name(encoded) hexdump(bytearray(decoded[1],'utf-8')) #self.assertTrue(nmb.TYPE_SERVER==decoded[0]) self.assertTrue(name[:15]==decoded[1].strip())
def extract_info(self, packet): eth_packet = self.decoder.decode(packet) ip_packet = self.decoder.decode(packet).child() udp_packet = ip_packet.child() nbns_packet = nmb.NetBIOSPacket(udp_packet.child().get_packet()) nbns_name = nmb.decode_name(nbns_packet.get_answers())[1][0:15] nbns_type = ord(nmb.decode_name(nbns_packet.get_answers())[1][15]) return { 'source': [nbns_name, nbns_type], 'destination': None, 'station_id': mac_address(eth_packet.get_ether_shost().tolist()), 'reporter': [0, 0x800, 17, 137], 'protocol': [0, 0x800, 17, 137], 'timestamp': datetime.datetime.utcnow(), 'rawdata': packet, 'decode': eth_packet }