netaddr is a Python library for representing and manipulating network addresses.
Installing netaddr library:
Use any of following command to install netaddr library
$ sudo pip install netaddr
$ easy_install netaddr
Observe following example for more details:
>>> from netaddr import *
IPAddress(‘input ip’).is_private() will return true if the input ip address private, else it will return false.
We can use nmap command to ping all IP’s in subnet.
If you don’t have nmap installed in your machine install nmap with following command:
$ apt-get install nmap
Use following command to ping all IP’s in a subnet:
$ nmap -n -sP 192.168.2.0/26
Starting Nmap 5.21 ( http://nmap.org ) at 2014-06-30 17:04 PDT
Nmap scan report for 192.168.2.1
Host is up (0.00073s latency).
Nmap scan report for 192.168.2.2
Host is up (0.0011s latency).
Nmap scan report for 192.168.2.4
Host is up (0.0010s latency).
Nmap done: 64 IP addresses (3 hosts up) scanned in 0.62 seconds
In above output we can see all reachable IP’s.