Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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(''); 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

Replies are listed 'Best First'.
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(''); 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948798]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-05-25 17:35 GMT
Find Nodes?
    Voting Booth?