#!/bin/bash# Author: pr0b3r7# Check for argumentsif [[ "$1"=="" ]] ; then# Notify the user this script does not require arguments and display proper syntaxecho"[*] - This script requires the first three octets of the /24 network! - Usage: ./ping-sw.sh 192.168.1"else# Iterate over 1-255 (/24 subnet) ; ping each IP with 1 ICMP Echo Request# (cont.) display only the lines containing "64 bytes" (ICMP Echo Responses)# (cont.) & performs each ping at the same time ; Redirect standard error to /dev/null# (cont.) AWK prints the 4th column containing the IP address ; cut the first field using : as delimiter# (cont.) to print only the IP address without the trailing ":".for i in {1..255} ; doping-c1 $1.$i |grep"64 bytes"&done2> /dev/null |awk'{print $4}'|cut-d":"-f1fi
Optional :
Save ping**-**sw.sh script **output **to a text file :
./ping-sw.sh 192.168.1 > iplist.txt
Show contents of iplist.txt and **sort **by unique value
cat iplist | sort -unique
** Creative usage: **
For loop to do basic scan of the** IPs in the list **and save to text file
for ip in $(cat iplist.txt); do nmap -Pn $ip; done > nmapresults.txt