Skip to content
zeknox edited this page Oct 23, 2012 · 1 revision

pingsweep.rb

This ruby script will help discovery live hosts on a network through the use of ICMP. This script is dependent on an installed and running version of nmap. Additionally the script is dependent on the ruby gem netaddr

Define subnets

Define the subnets you would like to scan in CIDR notation only.

root@bt:~# cat subnets.txt 
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
192.168.4.0/24
192.168.5.0/24
192.168.6.0/24
192.168.7.0/24
192.168.8.0/24

Execute pingsweep.rb

Execute the pingsweep command against the targeted subnets in the file

root@bt:~# ruby pingsweep.rb subnets.txt 
[+] Running pingsweep scan against 192.168.0.0/24
[+] 8 live hosts in 192.168.0.0/24
[+] Writing live hosts to file: /root/hosts/192.168.0.0_hosts.txt
[+] Running pingsweep scan against 192.168.1.0/24
[-] No live hosts in network: 192.168.1.0/24
[+] Running pingsweep scan against 192.168.2.0/24
[-] No live hosts in network: 192.168.2.0/24
[+] Running pingsweep scan against 192.168.3.0/24
[-] No live hosts in network: 192.168.3.0/24
[+] Running pingsweep scan against 192.168.4.0/24
[-] No live hosts in network: 192.168.4.0/24
[+] Running pingsweep scan against 192.168.5.0/24
[-] No live hosts in network: 192.168.5.0/24
[+] Running pingsweep scan against 192.168.6.0/24
[-] No live hosts in network: 192.168.6.0/24
[+] Running pingsweep scan against 192.168.7.0/24
[-] No live hosts in network: 192.168.7.0/24
[+] Running pingsweep scan against 192.168.8.0/24
[-] No live hosts in network: 192.168.8.0/24

Output

The script will output the raw nmap output to the pingsweep directory as shown below:

root@bt:~# ls -l pingsweep
total 108
-rw-r--r-- 1 root root  479 2012-10-02 19:04 192.168.0.0_sweep.gnmap
-rw-r--r-- 1 root root 1015 2012-10-02 19:04 192.168.0.0_sweep.nmap
-rw-r--r-- 1 root root 2695 2012-10-02 19:04 192.168.0.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:08 192.168.1.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:08 192.168.1.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:08 192.168.1.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:11 192.168.2.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:11 192.168.2.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:11 192.168.2.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:15 192.168.3.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:15 192.168.3.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:15 192.168.3.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:18 192.168.4.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:18 192.168.4.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:18 192.168.4.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:21 192.168.5.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:21 192.168.5.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:21 192.168.5.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:25 192.168.6.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:25 192.168.6.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:25 192.168.6.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:28 192.168.7.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:28 192.168.7.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:28 192.168.7.0_sweep.xml
-rw-r--r-- 1 root root  211 2012-10-02 19:32 192.168.8.0_sweep.gnmap
-rw-r--r-- 1 root root  211 2012-10-02 19:32 192.168.8.0_sweep.nmap
-rw-r--r-- 1 root root  727 2012-10-02 19:32 192.168.8.0_sweep.xml

The script will output the live hosts into the "hosts" folder as shown below. There is only one file in the hosts folder because all other networks did not have any live hosts on the subnet.

root@bt:~# ls -l hosts/
total 4
-rw-r--r-- 1 root root 110 2012-10-02 19:04 192.168.0.0_hosts.txt

View the live hosts:

root@bt:~# cat hosts/192.168.0.0_hosts.txt 
192.168.0.1
192.168.0.100
192.168.0.107
192.168.0.108
192.168.0.117
192.168.0.123
192.168.0.130
192.168.0.131
Clone this wiki locally