GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  TIE::NETADDR::IP (3)

.ds Aq ’

NAME

Tie::NetAddr::IP - Implements a Hash where the key is a subnet

CONTENTS

SYNOPSIS



  use Tie::NetAddr::IP;

  my %WhereIs;
 
  tie %WhereIs, Tie::NetAddr::IP;

  $WhereIs{"10.0.10.0/24"} = "Lab, First Floor";
  $WhereIs{"10.0.20.0/24"} = "Datacenter, Second Floor";
  $WhereIs{"10.0.30.0/27"} = "Remote location";
  $WhereIs{"0.0.0.0/0"} = "God knows where";

  foreach $host ("10.0.10.1", "10.0.20.15", "10.0.32.17", "10.10.0.1") {
     print "Host $host is in ", $WhereIs{$host}, "\n";
  }

  foreach $subnet (keys %WhereIs) {
     print "Network ", $subnet, " is used in ",
     $WhereIs{$subnet}, "\n";
  }

  untie %WhereIs;



DESCRIPTION

This module overloads hashes so that the key can be a subnet as in <B>NetAddr::IPB>. When looking values up, an interpretation will be made to find the given key <B>withinB> the subnets specified in the hash.

The code sample provided on the <B>SYNOPSISB> would print out the locations of every machine in the foreach loop.

Care must be taken, as only strings that can be parsed as an IP address by <B>NetAddr::IPB> can be used as keys for this hash.

Iterators on the hash such as foreach, each, keys and values will only see the actual subnets provided as keys to the hash. When looking up a value such as in $hash{$ipaddress} this IP address will be looked up among the subnets existing as keys within the hash. The matching subnet with the longest mask (ie, the most specific subnet) will win and its associated value will be returned.

This code can be distributed freely according to the terms set forth in the PERL license provided that proper credit is maintained. Please send bug reports and feedback to the author for further improvement.

HISTORY

0.01 original version; created by h2xs 1.19
1.00 Renamed to Tie::NetAddr::IP to match the modulelist name
1.50 Modified to use NetAddr::IP v3.00. Added a number of new tests
1.51 General update. Patch from Kazuyuki Maejima to fix bug related to keys, next, each, etc.

AUTHOR

Luis E. Munõz (luismunoz@cpan.org)

SEE ALSO

perl(1), NetAddr::IP(3).

POD ERRORS

Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 216: Non-ASCII character seen before =encoding in ’Munõz’. Assuming ISO8859-1
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 IP (3) 2003-02-09

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.