IP range/network scanner
We can use ICMP packets to create a network scanner. As ICMP is not an IP protocol, we have to access the network stack directly. So, here we can use Scapy to generate an ICMP packet and send it to the host.
Getting ready
To start the scraping, we have to install the required Python packages. Here we use Scapy for the packet generation. To install Scapy, we can use pip
. As we are using Python 3, make sure to install Scapy for Python 3. Also install its dependency module, netifaces
:
pip3 install scapy-python3pip3 install netifaces
How to do it...
Here are the steps for creating a simple network scanner using the scapy
module:
- Create a file called
network-scanner.py
and open it in your editor. - Import the required modules for the script:
import socket, re
from scapy.all import *
- To get the local IP of the system, we use the
getsockname
method in thesocket
module. However, it require a connection. So, we create a UDP socket connection to connect to Google DNS and use this connection...