Solved

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

Posted on 2012-04-11
5
763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

726 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