Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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]
[choroba]: It has the widest rear seats space available in the same price category - needed for the 3 kids.
Discipulus families growth is related to price of cars nowadays..
[choroba]: price of anything, unfortunately
[Discipulus]: yes, unfortunately.
[Corion]: Discipulus: you can "easily" trap shutdown/logoff in a Win32::GUI application by capturing and responding to the appropriate message
[LanX]: choroba wants to scale further? :)
[Discipulus]: I read an article about how much the female condition has got worst in the eastern europe after the fall of social policies
LanX has a friend in Berlin who switched to go(lang) and just got a kid ...
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-01-17 09:43 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (154 votes). Check out past polls.