Solved

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

Posted on 2012-04-11
5
764 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Creating an OSPF network that automatically (dynamically) reroutes network traffic over other connections to prevent network downtime.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

691 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