Get all ip address from subnet mask


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get all ip address from subnet mask
# 1  
Old 06-19-2013
Get all ip address from subnet mask

I have this subnet file shown below. How can I calculate all ip addresses from that list
Code:
103.22.200.0/22 
141.101.64.0/18
10.0.0.0/22

I need to be able to read the subnet file and print all IPs in those subnet to an out put file
# 2  
Old 06-19-2013
There will be thousands and thousands. Just comparing would be simpler and more effective than generating an exhaustive list.
# 3  
Old 06-19-2013
Let say we have a subnet file that has 2 line

Code:
10.10.0.0/26
11.00.00.0/26

How would you list those ips in those subnets?
# 4  
Old 06-19-2013
It'd make sense to compare instead of printing a comprehensive list. Subnets work the way they do because it's very easy to compare an IP to a subnet and mask with logical operations.

But if you insist I'll show you a way. It requires a 3.0+ BASH shell.

Code:
#!/bin/bash

printsubnet() {
        local OLDIFS="$IFS"
        local SUB=${1/\/*/}
        local MASK=$(( 1 << ( 32 - ${1/*\//} )))

        IFS="."
                set -- $SUB
                IPS=$((0x$(printf "%02x%02x%02x%02x\n" $1 $2 $3 $4)))
        IFS="$OLDIFS"

        for ((N=0; N<MASK; N++))
        {
                VAL=$((IPS|N))

                printf "%d.%d.%d.%d\n"                  \
                        $(( (VAL >> 24) & 255 ))        \
                        $(( (VAL >> 16) & 255 ))        \
                        $(( (VAL >> 8 ) & 255 ))        \
                        $(( (VAL)       & 255 ))
        }
}

printsubnet 172.16.0.0/16

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Changing the subnet mask on solaris 10

Hello, can anyone help me with the command to change the subnet mask on solaris 10? The mask is currently 255.255.255.255 I will like to change it to 255.255.2555.0. Thank you (5 Replies)
Discussion started by: cjashu
5 Replies

2. IP Networking

lookup ip address, subnet mask, gateway, and dns at same time

Is there a command that can lookup ip address, subnet mask, gateway, and dns all at the same. I know ifconfig can lookup ip address and subnet mask. I know route -n can lookup gateway. Not sure about a dns command. So I hope there is a way to lookup ip address, subnet mask, gateway, and dns all at... (2 Replies)
Discussion started by: cokedude
2 Replies

3. AIX

Changing subnet mask for a NIM Network.

I am new to this forum so please bare with me. I did search for this answer prior to posting but no luck. Running an AIX NIM Master at 5.3TL9SP4, with about 100 clients. The subnet of one of the networks defined in the NIM env has changed. When I go to Manage Networks, Change/Show... (0 Replies)
Discussion started by: juredd1
0 Replies

4. Solaris

how to change the subnet mask of interface

Hi all, could you please tell me how to Change the subnet mask of interface aded:1 from ffffffc0 to ffffff80 regards Krishna (7 Replies)
Discussion started by: murthy76
7 Replies

5. Solaris

Need help in changing the subnet mask

Hi, I have a task to edit the subnet mask in almost 100+ solaris servers.Few of the servers are configured with IPMP.There will be no change of IP address or default gateway.If its a single IP we can bring NIC down,change the subnet mask in /etc/netmasks,then bring the NIC back to normal.But... (3 Replies)
Discussion started by: rajip23
3 Replies

6. IP Networking

Static IP / Subnet mask and Gateway

Hi all, I installed Fedora 9 + squid at one of PC at work. Our company has windows 2003 servera acting as DHCP server. During installation, i set linux box up as Static IP (192.168.0.100) But once installation completed, The pc is assigned a different IP address instead of 192.168.0.100.... (3 Replies)
Discussion started by: c00kie88
3 Replies

7. IP Networking

changing the subnet mask permanently

I understand how to change the ip address permanently however, I need to also make a permanent change to the subnet mask. How would I accomplish this. (5 Replies)
Discussion started by: johnparksjr
5 Replies

8. IP Networking

How do I mask my MAC address

I posted this thread under BSD but realized that it actually belongs here instead.... makes more sense to put it under IP. So without further delay on to my problem ... I havent been using UNIX for that long, so this question might sound quite stupid to most of you. I want to know how to mask my... (2 Replies)
Discussion started by: PenguinDevil
2 Replies

9. IP Networking

Subnet mask

Hi, I have about 30 computers for users with subnet mask x.x.x.0, and 25 computers for workers with s.m. x.x.x.128. My server has a s.m. x.x.x.128 so with workers computers I can see my server and all the computers in that s.m., but I can't see the server from the users computers and I need to see... (7 Replies)
Discussion started by: Z0DiaC
7 Replies
Login or Register to Ask a Question