Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: ip address list

by wwe (Friar)
on Jan 19, 2012 at 16:03 UTC ( #948798=note: print w/ replies, xml ) Need Help??


in reply to ip address list

Hi mlebel,

this produces a list you are looking for

use strict; use warnings; use Net::Netmask; my $block = Net::Netmask->new('192.168.1.128/25'); print "1st element: ", $block->nth(1), "\n"; print "last element: ", $block->nth(-2), "\n"; my $i = 1; while (1) { print "ip adress #$i:", $block->nth($i), "\n"; last if $block->nth($i) eq $block->nth(-2); $i++; }
Maybe there is a better method in the Net::Netmask


Comment on Re: ip address list
Download Code
Re^2: ip address list
by mlebel (Hermit) on Jan 19, 2012 at 17:22 UTC

    Thanks wwe! It does just about what I need. I have modified it slightly to get the results that I was looking for. Here is the code:

    #!/usr/bin/perl use strict; use warnings; use Net::Netmask; my $block = Net::Netmask->new('10.2.9.0/29'); my $i = 1; while (1) { print $block->nth($i), "\n"; last if $block->nth($i) eq $block->nth(-2); $i++; }

    All I need to do now is to find a way to remove the first ip(the gateway ip)... any suggestions? thanks

Re^2: ip address list
by wwe (Friar) on Jan 20, 2012 at 12:43 UTC
    Hi mlebel

    as you may know this is not a code writing service. I'm glad to help you but you should also make your own efforts.

    The code I provided creates a network object and loops over all adresses inside of network. I think it is very easy to find out how to exclude the first address.

      thanks wwe..

      If I knew how to write it, i wouldn't be asking for help on this forum.

      If you don't want to help, then please keep your help and comments for yourself in the future. We are all here to learn and help eachother out.

      I for one have given full answers to others many times online in the past..

      This code is part of a much bigger script and Oh, I wrote all of the rest.. it's normal not to know the answer to something at some point. Lucky for you, I didn't ask how to incorporate the results into an array or anything else like that, I figured all that out by my self.. would you like to have the answer?(this way I can share back with you)

      Besides, this will most likely help someone else in the future also. Are you against that too?

      Thanks for your help anyway

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948798]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-11-28 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (193 votes), past polls