Subnet / Subnet Mask ---> IP calculation

K

kielhd

Hi NG,

I'm looking for a small script which would return all possible IPs
within a given Subnet and corresponding Subnet Mask.
ie: input: Subnet 10.152.186.0, Subnet Mask 255.255.255.192
output: 10.152.186.0, 10.152.186.1, 10.152.186.2 ... 10.152.186.63

Thanks!
Henning
 
A

Anno Siegel

kielhd said:
Hi NG,

I'm looking for a small script which would return all possible IPs
within a given Subnet and corresponding Subnet Mask.
ie: input: Subnet 10.152.186.0, Subnet Mask 255.255.255.192
output: 10.152.186.0, 10.152.186.1, 10.152.186.2 ... 10.152.186.63

What have you tried so far?

We help people with their Perl programs, but we don't do contract work.
Find a newsgroup with "jobs" in the title for that.

Anno
 
B

Brian McCauley

I'm looking

When you say "I'm looking" can you explain what form this looking has
taken? Perhaps we could then advise you on how to look more
effectively.

There's a module to do exactly what you describe in the usual place
(see FAQ).

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
J

John W. Krahn

kielhd said:
I'm looking for a small script which would return all possible IPs
within a given Subnet and corresponding Subnet Mask.
ie: input: Subnet 10.152.186.0, Subnet Mask 255.255.255.192
output: 10.152.186.0, 10.152.186.1, 10.152.186.2 ... 10.152.186.63

use Socket;
sub range {
my ( $sub, $mask ) = map unpack( 'N', inet_aton( $_ ) ), @_;
map inet_ntoa( pack( 'N', $sub | $_ ) ), $sub & ~$mask .. ~$mask;
}

print for range( '10.152.186.0', '255.255.255.192' );


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top