Solved

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

Posted on 2012-04-11
5
762 Views
Last Modified: 2012-04-22
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 !
0
Comment
Question by:hintco
5 Comments
 
LVL 17

Accepted Solution

by:
Anuroopsundd earned 100 total points
ID: 37831998
0
 
LVL 4

Expert Comment

by:senseifedon
ID: 37839300
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

0
 
LVL 4

Expert Comment

by:senseifedon
ID: 37845900
hintco are you there?
0
 
LVL 1

Author Comment

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

thank you !
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37855938
--
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VMware Workstation 12 Player 16 74
how to print sub line with  sed /awk /perl in bash file 11 24
linux 13 49
Linux Real Time Memory on Distinct 24 Cycle 7 18
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question