first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import unittest
|
||||
|
||||
from librenet_scanner.network import NetworkInterface, target_is_on_interface, validate_target
|
||||
from librenet_scanner.parsers import parse_arp_scan, parse_nmap_xml
|
||||
|
||||
|
||||
class ParserTests(unittest.TestCase):
|
||||
def test_arp_scan_parser(self):
|
||||
text = """Interface: eth0, type: EN10MB\n192.168.1.10\t00:11:22:33:44:55\tHewlett Packard\n192.168.1.20\taa:bb:cc:dd:ee:ff\t(Unknown)\n2 packets received\n"""
|
||||
hosts = parse_arp_scan(text)
|
||||
self.assertEqual(len(hosts), 2)
|
||||
self.assertEqual(hosts[0].ip, "192.168.1.10")
|
||||
self.assertEqual(hosts[0].mac, "00:11:22:33:44:55")
|
||||
self.assertEqual(hosts[0].vendor, "Hewlett Packard")
|
||||
self.assertEqual(hosts[1].vendor, "")
|
||||
|
||||
def test_nmap_parser(self):
|
||||
xml = """<?xml version='1.0'?>
|
||||
<nmaprun>
|
||||
<host>
|
||||
<status state='up'/>
|
||||
<address addr='192.168.1.10' addrtype='ipv4'/>
|
||||
<address addr='00:11:22:33:44:55' addrtype='mac' vendor='HP'/>
|
||||
<hostnames><hostname name='pc-test.local'/></hostnames>
|
||||
<ports>
|
||||
<port protocol='tcp' portid='22'><state state='open'/><service name='ssh' product='OpenSSH' version='9.2'/></port>
|
||||
</ports>
|
||||
<os><osmatch name='Linux 6.x'/></os>
|
||||
</host>
|
||||
</nmaprun>"""
|
||||
hosts = parse_nmap_xml(xml)
|
||||
self.assertEqual(len(hosts), 1)
|
||||
host = hosts[0]
|
||||
self.assertEqual(host.hostname, "pc-test.local")
|
||||
self.assertEqual(host.vendor, "HP")
|
||||
self.assertEqual(host.os_name, "Linux 6.x")
|
||||
self.assertEqual(host.ports[0].port, 22)
|
||||
self.assertEqual(host.ports[0].service, "ssh")
|
||||
|
||||
def test_target_normalization(self):
|
||||
self.assertEqual(validate_target("192.168.1.42/24"), "192.168.1.0/24")
|
||||
self.assertEqual(validate_target("10.0.0.7"), "10.0.0.7")
|
||||
|
||||
def test_interface_targeting(self):
|
||||
iface = NetworkInterface("eth0", "192.168.1.10", 24, "192.168.1.0/24", False)
|
||||
self.assertTrue(target_is_on_interface("192.168.1.0/24", iface))
|
||||
self.assertTrue(target_is_on_interface("192.168.1.128/25", iface))
|
||||
self.assertFalse(target_is_on_interface("192.168.0.0/16", iface))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user