ip range addresses


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ip range addresses
# 1  
Old 06-21-2010
ip range addresses

I am trying to find a script that will generate all the ip addresses in particular range.

Example: start: 41.0.0.0 end ip 41.1.1.2

32.32.35.3 to 32.32.36.0


Please help.

Thanks
# 2  
Old 06-21-2010
There was a recent thread about that subject here: https://www.unix.com/showthread.php?t=137518
# 3  
Old 06-21-2010
Quote:
Originally Posted by Scrutinizer
There was a recent thread about that subject here: https://www.unix.com/showthread.php?t=137518
awk -F. 'NR==1 {pre=$1"."$2; a=$3; d=$4} NR==2 {b=$3; c=$4} END {for(i=a;i<=b;i++) for(j=d;j<=c;j++) print pre"."i"."j}' input_file

works great if the input file is like

192.168.0.1
192.168.3.1


but my input is a bit different: 192.168.0.1 192.168.3.1

just need a little tweak for awk i guess.

Thanks
# 4  
Old 06-21-2010
Hi, i modified the awk to make it more universal. It does not take netmasks into account or anything so it includes broadcast addresses for instance.
Code:
awk 'NR==1{split($1,A,".")}
     NR==2{split($1,B,".")}
     END  {for(i=A[1];i<=B[1];i++)
             for(j=A[2];j<=((i==B[1])?B[2]:255);j++)
               for(k=A[3];k<=((j==B[2])?B[3]:255);k++)
                 for(l=A[4];l<=((k==B[3])?B[4]:255);l++)
                   print i"."j"."k"."l}' infile


Last edited by Scrutinizer; 06-21-2010 at 05:16 PM..
# 5  
Old 06-21-2010
Place this awk code in a file.
Code:
BEGIN { FS="[. ]" }
END {
    a1=$1; b1=$2; c1=$3; d1=$4;
    a2=$5; b2=$6; c2=$7; d2=$8;

    while( d2 >= d1 || c2 > c1 || b2 > b1 || a2 > a1) {
       if (d1 > 255) { d1=1; c1++; }
       if (c1 > 255) { c1=1; b1++; }
       if (b1 > 255) { b1=1; a1++; }
       print a1"."b1"."c1"."d1
       d1++
    }
}

Suppose you name this file ip.awk. Then
Code:
$ echo "192.168.0.1 192.168.3.1" | awk -f ip.awk

generates an inclusive list of all IP addresses between 192.168.0.1 and 192.168.3.1, one per line.
# 6  
Old 06-21-2010
super thank you.
# 7  
Old 06-21-2010
Most recent Linux distro's have ipcalc that will perform this very operation. Smilie


Linux Calculating Subnets with ipcalc and sipcalc Utilities
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print range between two patterns if it contains a pattern within the range

I want to print between the range two patterns if a particular pattern is present in between the two patterns. I am new to Unix. Any help would be greatly appreciated. e.g. Pattern1 Bombay Calcutta Delhi Pattern2 Pattern1 Patna Madras Gwalior Delhi Pattern2 Pattern1... (2 Replies)
Discussion started by: joyan321
2 Replies

2. Shell Programming and Scripting

Extract IP addresses

The only way I could extract the user names and 'from' IP addresses is to use a few temp files. Split up by 'Failed keyboard-interactive' and 'Failed password'. Anyone have any idea to do this all in one go? aaa.bbb.ccc.ddd 2009-03-23 01:28:33 sshd: Failed keyboard-interactive/pam... (2 Replies)
Discussion started by: hazno
2 Replies

3. UNIX for Dummies Questions & Answers

Different ip addresses

Hello! I have logged in using Putty into another machine 'tele'. The ip address which i used to login to 'tele' is 192.168.1.3. Now while at 'tele' when i run "#ifconfig -a" i get the same ip address i.e, 192.168.1.3. But when i run "#arp tele" it gives the output: tele (10.143.128.8) ... (9 Replies)
Discussion started by: suhail.sadaqat
9 Replies

4. UNIX and Linux Applications

email addresses

Greetings to all. I have installed dadamail on my web site and it works extremely well. I have two questions: 1. I have modified dada to bounce bad emails, but only the first newsletter will use the modifications. If I create another list, it doesn't use the modification. What gives? 2. Are... (0 Replies)
Discussion started by: okbrowder
0 Replies

5. Programming

LInear Addresses

Hi all, Even after reading many explanation the question still haunting me what's the difference between physical and linear addresses.Can we directly access physical addresses .If not then paging circuitry would have ensure contiguous physical addresses regardless of any linear addresses but this... (2 Replies)
Discussion started by: joshighanshyam
2 Replies

6. Programming

memory addresses

you have three variables of type char, int and float in continous memory locations. How do you print the contents of each of these.??? Thanks in advance. (0 Replies)
Discussion started by: areef4u
0 Replies

7. Programming

memory addresses

where is addresses(what kind of memory) like this one "df605d50". I want to print address of locan variable: printf("&i - %p", &i); and I have &i - df605d50. (0 Replies)
Discussion started by: Paravozzz
0 Replies

8. IP Networking

Ip Addresses

I'm not exactly sure what I can do with IPs... my friend won't tell me(don't ask me why, I figure it's cause he doesn't know either, hehe). I'm curious as to what theya re used for other than networking computers... if there IS any other purpose or use for them. That's all. --Evil_d00d (4 Replies)
Discussion started by: evil_d00d
4 Replies

9. IP Networking

ip addresses

this might sound corny but i need help finding out about finding a persons ip address can u halp? and another question what the hell does ping mean??? thank u. (2 Replies)
Discussion started by: dragonslayer100
2 Replies

10. IP Networking

Finding IP Addresses

Is there anyway to tell what my NT IP is while logging into my UNIX box. I have users accessing our NT network and then telneting into our Unix Box. I would like to restrict access somehow. My who commands only returns the users name and pts device which changes. (1 Reply)
Discussion started by: golfs4us
1 Replies
Login or Register to Ask a Question