Shell Scripting – Ping Sweep Script

Shell scripting: ping sweep

In this series you have already seen basics and some  example of automation, let’s dive into more applicative use of shell script, ping sweep is something very basic that every network administrator do, and its obvious that they don’t do it in the usual way because it’s not practical to ping sweep whole network again and again through console by typing the long commands, they use shell scripting and make a shell script to do the task for them in just one click.

What is ping sweep?

In computing, a ping sweep is a method that can establish a range of IP addresses which map to live hosts.

The classic tool used for ping sweeps is fping, which traditionally was accompanied by gping to generate the list of hosts for large subnets, although a more recent version of fping includes that functionality. Well-known tools with ping sweep capability include nmap for Unix systems and the Pinger software from Rhino9 for Windows NT. There are many other tools with this capability, including: Hping, Simple Nomad’s ICMPEnum, SolarWind’s Ping Sweep, and Foundstone’s SuperScan. There is also a ping sweep tool for Windows, Mac, Linux, Android, and iOS called Fing made by Overlook Soft.

Pings can be detected by protocol loggers like ippl.

In the video above step by step demonstration of ping sweep through a shell script has been shown, have a look for better understanding.

Here is the program:

#!/bin/bash

Echo “enter your subnet”

Read SUBNET

for IP in $(seq 100,254); do

            ping -c 1 $SUBNET.$IP

done

when you run this script with right permissions, it will ask you to enter the subnet(ex 192.168.0), when you enter subnet then it will ping the respective address by adding the IP values which is in this case between (100-254), the -c is for count of packets which is 1 in the above example, which means the script will send 1 ICMP echo request packet to the target machine, if the target machine is up then you will receive a packet from the target machine.

Hence you have learned another way to automate a task with shell scripting, stay tuned as lot of other videos are coming, keep learning.

Share!

Leave a Reply