T
T
TODO•SEC
Search…
Check for live hosts in a /24 network
1
#!/bin/bash
2
# Author: pr0b3r7
3
4
# Check for arguments
5
if [[ "$1" == "" ]] ; then
6
# Notify the user this script does not require arguments and display proper syntax
7
echo "[*] - This script requires the first three octets of the /24 network! - Usage: ./ping-sw.sh 192.168.1"
8
else
9
# Iterate over 1-255 (/24 subnet) ; ping each IP with 1 ICMP Echo Request
10
# (cont.) display only the lines containing "64 bytes" (ICMP Echo Responses)
11
# (cont.) & performs each ping at the same time ; Redirect standard error to /dev/null
12
# (cont.) AWK prints the 4th column containing the IP address ; cut the first field using : as delimiter
13
# (cont.) to print only the IP address without the trailing ":".
14
for i in {1..255} ; do ping -c 1 $1.$i | grep "64 bytes" & done 2> /dev/null | awk '{print $4}' | cut -d ":" -f 1
15
fi
Copied!
sample run + source
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
Last modified 8d ago
Copy link