Skip to content

Bash

Scripting with bash

#!/bin/bash
for ip in `seq 1 254`; do
ping -c 1 $1.$ip | grep "64 bytes" | cut -d " " -f 4 | tr -d ":" &
done
./pingsweep.sh 192.168.4

Where: 

`seq 1 254` =  sequence starting from 1 to 254 [pay attention to the backticks “]

-c 1 = count 1 

$1 = user input [the first 3 octets of the network in this case]

.$ip = the sequence starting with 1 to 254

-d = delimiter

tr = translate

& = allows multithreading [ping all the IPs at once]
  • Other usefull ways to use it with nmap

Note

You need to run the command in the same directory where pingsweep.sh file is located.

./pingsweep.sh 192.168.2 > ips.txt Scan the TCP port 80 for all active IPs in the ips.txt by executing the following line in the terminal:

for ip in $(cat ips.txt); do nmap -p 80 -T4 $ip & done This is how you interpret the above command: For “ip” in the “ips.txt” file, run nmap, and scan the port “-p” 80 at speed “-T4” for every IP “$ip” simultaneously “&” and finish “done”.