NetworkScanner (version 2.0.0) | index networkscanner.py |
This module implements a passive NetworkScanner and an active NetworkScanner
using ARP and ping scan IP sweep and hostname resolution.
~# python3 NetworkScanner.py -I -t 172.18.0.1-172.18.0.15
172.18.0.9
172.18.0.13
172.18.0.14
172.18.0.10
~# python3 NetworkScanner.py -d --async --noping --hostname --ports 22 80 -p 445 139 443 -T 1 -R -t 172.18.0.0/28
[2016-06-22 05:01:12] DEBUG (10) {__main__ - NetworkScanner.py:490} Build NetworkScanner...
[2016-06-22 05:01:12] DEBUG (10) {__main__ - NetworkScanner.py:501} Configure real time...
[2016-06-22 05:01:12] DEBUG (10) {__main__ - NetworkScanner.py:509} The scan begins...
[2016-06-22 05:01:12] INFO (20) {__main__ - NetworkScanner.py:295} Run asynchronous scan (without scapy).
[2016-06-22 05:01:12] INFO (20) {__main__ - NetworkScanner.py:204} Start asynchronous scan without scapy...
[2016-06-22 05:01:12] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.11' (step 1: PING)...
[2016-06-22 05:01:12] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.11' (step 2: HOSTNAME)...
[2016-06-22 05:01:21] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.11' (step 3: TCP connections)...
[2016-06-22 05:01:21] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.2' (step 1: PING)...
[2016-06-22 05:01:21] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.2' (step 2: HOSTNAME)...
[2016-06-22 05:01:30] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.2' (step 3: TCP connections)...
[2016-06-22 05:01:30] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.3' (step 1: PING)...
[2016-06-22 05:01:30] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.3' (step 2: HOSTNAME)...
[2016-06-22 05:01:39] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.3' (step 3: TCP connections)...
[2016-06-22 05:01:39] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.7' (step 1: PING)...
[2016-06-22 05:01:39] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.7' (step 2: HOSTNAME)...
[2016-06-22 05:01:48] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.7' (step 3: TCP connections)...
[2016-06-22 05:01:48] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.4' (step 1: PING)...
[2016-06-22 05:01:48] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.4' (step 2: HOSTNAME)...
[2016-06-22 05:01:57] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.4' (step 3: TCP connections)...
[2016-06-22 05:01:57] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.13' (step 1: PING)...
[2016-06-22 05:01:57] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.13' (step 2: HOSTNAME)...
[2016-06-22 05:02:03] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.13' (step 3: TCP connections)...
[2016-06-22 05:02:03] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.14' (step 1: PING)...
[2016-06-22 05:02:03] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.14' (step 2: HOSTNAME)...
[2016-06-22 05:02:07] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.14' (step 3: TCP connections)...
[2016-06-22 05:02:07] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.6' (step 1: PING)...
[2016-06-22 05:02:08] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.6' (step 2: HOSTNAME)...
[2016-06-22 05:02:17] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.6' (step 3: TCP connections)...
[2016-06-22 05:02:17] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.10' (step 1: PING)...
[2016-06-22 05:02:17] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.10' (step 2: HOSTNAME)...
[2016-06-22 05:02:21] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.10' (step 3: TCP connections)...
[2016-06-22 05:02:21] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.8' (step 1: PING)...
[2016-06-22 05:02:21] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.8' (step 2: HOSTNAME)...
[2016-06-22 05:02:26] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.8' (step 3: TCP connections)...
[2016-06-22 05:02:26] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.5' (step 1: PING)...
[2016-06-22 05:02:26] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.5' (step 2: HOSTNAME)...
[2016-06-22 05:02:35] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.5' (step 3: TCP connections)...
[2016-06-22 05:02:35] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.9' (step 1: PING)...
[2016-06-22 05:02:35] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.9' (step 2: HOSTNAME)...
[2016-06-22 05:02:40] DEBUG (10) {__main__ - NetworkScanner.py:317} Start handle_UP for '172.18.0.9'...
[2016-06-22 05:02:40] DEBUG (10) {__main__ - NetworkScanner.py:319} Quit handle_UP for '172.18.0.9'.
[2016-06-22 05:02:40] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.1' (step 1: PING)...
[2016-06-22 05:02:40] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.1' (step 2: HOSTNAME)...
[2016-06-22 05:02:49] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.1' (step 3: TCP connections)...
[2016-06-22 05:02:49] DEBUG (10) {__main__ - NetworkScanner.py:350} Check '172.18.0.12' (step 1: PING)...
[2016-06-22 05:02:49] DEBUG (10) {__main__ - NetworkScanner.py:355} Check '172.18.0.12' (step 2: HOSTNAME)...
[2016-06-22 05:02:58] DEBUG (10) {__main__ - NetworkScanner.py:365} Check '172.18.0.12' (step 3: TCP connections)...
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.14' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.6' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.3' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.13' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.11' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.4' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.7' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.5' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.8' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.2' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.10' is probably not up.
[2016-06-22 05:03:02] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.1' is probably not up.
[2016-06-22 05:03:03] DEBUG (10) {__main__ - NetworkScanner.py:381} '172.18.0.12' is probably not up.
[2016-06-22 05:03:03] DEBUG (10) {__main__ - NetworkScanner.py:215} Start ARP detection...
[2016-06-22 05:03:04] INFO (20) {__main__ - NetworkScanner.py:227} Scan end.
[2016-06-22 05:03:04] DEBUG (10) {__main__ - NetworkScanner.py:511} Scan end.
UP: 172.18.0.9
DOWN:
~# python NetworkScanner.py -d -I -t 172.18.0.0/28
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:651} Build NetworkScanner...
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:662} Configure real time...
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:670} The scan begins...
[2016-06-22 05:02:24] INFO (20) {__main__ - NetworkScanner.py:445} Run scapy scan.
[2016-06-22 05:02:24] INFO (20) {__main__ - NetworkScanner.py:385} Start AsyncSniffer using Scapy...
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:402} Sending ARP packets...
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.6'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.9'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.8'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.5'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.10'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.13'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.14'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.4'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.7'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.3'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.12'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.11'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.1'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:309} Send ARP packet for '172.18.0.2'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:407} Sending ICMP packets...
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.6'
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:369} ARP detected in packet...
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:470} Start handle_UP for '172.18.0.9' (ARPa4:ee:57:35:c0:a8)...
172.18.0.9
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:476} Quit handle_UP for '172.18.0.9'.
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:369} ARP detected in packet...
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:470} Start handle_UP for '172.18.0.10' (ARP62:66:e6:d0:e0:b0)...
172.18.0.10
[2016-06-22 05:02:24] DEBUG (10) {__main__ - NetworkScanner.py:476} Quit handle_UP for '172.18.0.10'.
[2016-06-22 05:02:26] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.9'
[2016-06-22 05:02:26] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.8'
[2016-06-22 05:02:28] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.5'
[2016-06-22 05:02:30] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.10'
[2016-06-22 05:02:32] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.13'
[2016-06-22 05:02:34] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.14'
[2016-06-22 05:02:36] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.4'
[2016-06-22 05:02:38] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.7'
[2016-06-22 05:02:40] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.3'
[2016-06-22 05:02:42] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.12'
[2016-06-22 05:02:44] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.11'
[2016-06-22 05:02:46] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.1'
[2016-06-22 05:02:48] DEBUG (10) {__main__ - NetworkScanner.py:300} Send ICMP packet for '172.18.0.2'
[2016-06-22 05:02:50] DEBUG (10) {__main__ - NetworkScanner.py:414} Sending TCP packets...
[2016-06-22 05:02:50] DEBUG (10) {__main__ - NetworkScanner.py:420} Packets, are sent. Wait for timeout...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:426} Get IP addresses down...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.1'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.1'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.8'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.8'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.11'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.11'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.5'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.5'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.14'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.14'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.4'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.4'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.7'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.7'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.13'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.13'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.12'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.12'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.3'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.3'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.6'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.6'.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:497} Start handle_DOWN for '172.18.0.2'...
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:499} Quit handle_DOWN for '172.18.0.2'.
[2016-06-22 05:02:53] INFO (20) {__main__ - NetworkScanner.py:433} Stop AsyncSniffer, scan end.
[2016-06-22 05:02:53] DEBUG (10) {__main__ - NetworkScanner.py:672} Scan end.
~# python NetworkScanner.py --noping --hostname --ports 22 80 -p 445 139 443 -T 1 -R -t 172.18.0.0/28
[+] IP: '172.18.0.9' is UP and MAC address is '00:11:22:33:44:55'
[+] IP: '172.18.0.10' is UP and MAC address is 'aa:bb:cc:dd:ee:ff'
[-] IP: '172.18.0.13' is DOWN
[-] IP: '172.18.0.5' is DOWN
[-] IP: '172.18.0.12' is DOWN
[-] IP: '172.18.0.14' is DOWN
[-] IP: '172.18.0.7' is DOWN
[-] IP: '172.18.0.4' is DOWN
[-] IP: '172.18.0.11' is DOWN
[-] IP: '172.18.0.3' is DOWN
[-] IP: '172.18.0.6' is DOWN
[-] IP: '172.18.0.2' is DOWN
[-] IP: '172.18.0.1' is DOWN
[-] IP: '172.18.0.8' is DOWN
~#
~# python NetworkScanner.py -i 172.18.0. -P -t 172.18.0.0/28
[+] IP: '172.18.0.9' is UP and MAC address is '00:11:22:33:44:55'
[+] IP: '172.18.0.10' is UP and MAC address is 'aa:bb:cc:dd:ee:ff'
^C
~#
>>> from NetworkScanner import NetworkScanner, logger
>>> scanner = NetworkScanner({"172.18.0.1", "172.18.0.3"})
>>> scanner.scan() # Without scapy
IP: '172.18.0.1' is UP ('ARP', None).
IP: '172.18.0.3' is UP ('ARP', None).
[True, True]
>>> def do_IP_UP(ip, reason, detail = None):
... print(f"{ip} is UP ({reason} {detail})")
...
>>> scanner.handle_UP = do_IP_UP
>>> scanner.scan(True) # With scapy
172.18.0.1 is UP (ARP 01:02:03:04:05:06)
172.18.0.3 is UP (ARP FF:EE:DD:CC:BB:AA)
[True, True]
>>> scanner.hosts_up
['172.18.0.3', '172.18.0.1']
>>> scanner.hosts_down
[]
>>> from scapy.all import *
>>> scanner = NetworkScanner({"172.18.0.1"}, False, [22, 80], False, True, False, 1, conf.iface)
>>> scanner.handle_UP = do_IP_UP
>>> scanner.handle_DOWN = print
>>> scanner.scan()
172.18.0.1
[False]
>>> logger.setLevel(10) # debug mode
>>> scanner.scan(passive=True) # passive scan
>>>
Classes | ||||||||||
|
Functions | ||
|
Data | ||
__all__ = ['NetworkScanner', 'main'] __annotations__ = {'critical': <class 'collections.abc.Callable'>, 'debug': <class 'collections.abc.Callable'>, 'error': <class 'collections.abc.Callable'>, 'info': <class 'collections.abc.Callable'>, 'logger': <class 'logging.Logger'>, 'warning': <class 'collections.abc.Callable'>} __author_email__ = 'mauricelambert434@gmail.com' __copyright__ = '\nNetworkScanner Copyright (C) 2021, 2022, 2023 ...ome to redistribute it\nunder certain conditions.\n' __description__ = '\nThis module implements a passive NetworkScanner... and ping scan IP sweep and hostname resolution.\n' __license__ = 'GPL-3.0 License' __maintainer__ = 'Maurice Lambert' __maintainer_email__ = 'mauricelambert434@gmail.com' __url__ = 'https://github.com/mauricelambert/NetworkScanner' |
Author | ||
Maurice Lambert |