Solved

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

Posted on 2012-04-11
5
761 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
Comment Utility
0
 
LVL 4

Expert Comment

by:senseifedon
Comment Utility
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
Comment Utility
hintco are you there?
0
 
LVL 1

Author Comment

by:hintco
Comment Utility
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
Comment Utility
--
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now