Subnet / Subnet Mask ---> IP calculation

Discussion in 'Perl Misc' started by kielhd, Nov 6, 2003.

  1. kielhd

    kielhd Guest

    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
    kielhd, Nov 6, 2003
    #1
    1. Advertising

  2. kielhd

    Anno Siegel Guest

    kielhd <> wrote in comp.lang.perl.misc:
    > 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
    Anno Siegel, Nov 6, 2003
    #2
    1. Advertising

  3. (kielhd) writes:

    > 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\\
    Brian McCauley, Nov 6, 2003
    #3
  4. kielhd wrote:
    >
    > 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
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Nov 9, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Glenn M

    Get Requesting Clients Subnet Mask

    Glenn M, Oct 12, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    414
    John Saunders
    Oct 12, 2004
  2. Pierre Rouleau
    Replies:
    0
    Views:
    383
    Pierre Rouleau
    Dec 10, 2003
  3. yagru_alvarez
    Replies:
    7
    Views:
    597
    Michael Doubez
    Jun 6, 2011
  4. David Corticchiato

    Get the subnet mask

    David Corticchiato, Dec 19, 2006, in forum: Ruby
    Replies:
    3
    Views:
    168
    Shiwei Zhang
    Jan 12, 2007
  5. 187
    Replies:
    2
    Views:
    528
    Bart Lateur
    Jul 29, 2004
Loading...

Share This Page