Link to home
Start Free TrialLog in
Avatar of hintco
hintco

asked on

How to List all ip addresses on ip block or subnet !?

Hello ,

i need to write small bash script to list in loop all possible ip addresses in specific subnet or ip block.

example 1 :
ip block 192.168.1.0/24 will list :
192.168.1.1 - 192.168.1.254

example2:
192.168.1.96/27
will list the following ip addresses :
192.168.1.97 - 192.168.1.126

exmple 3:
172.16.0.0 / 20
will list the following ip addresses :
172.16.0.1 - 172.16.15.254

thank you !
ASKER CERTIFIED SOLUTION
Avatar of Anuroopsundd
Anuroopsundd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi;
Following script lists all possible ip address in range:

#!/bin/bash

is_alive_ping()
{
  ping -c 1 $1 > /dev/null
  [ $? -eq 0 ] && echo Node with IP: $i is up.
}

for i in 192.168.1.{1..255} 
do
is_alive_ping $i & disown
done

Open in new window


Then save the scipt as a named bash_ping_scan.sh

Execute the script file
./bash_ping_scan.sh

Open in new window


Sample output like this:

Node with IP: 192.168.1.1 is up.
Node with IP: 192.168.1.4 is up.
Node with IP: 192.168.1.9 is up.

Open in new window

hintco are you there?
Avatar of hintco
hintco

ASKER

senseifedon
right but i need something general for any type of subnet and networks not just class C network with subnet /24

thank you !
Avatar of woolmilkporc
--