1Array::IntSpan::IP(3) User Contributed Perl DocumentationArray::IntSpan::IP(3)
2
3
4
6 Array::IntSpan::IP - a Module for arrays using IP addresses as indices
7
9 use Array::IntSpan::IP;
10
11 my $foo = Array::IntSpan::IP->new(['123.45.67.0', '123.45.67.255', 'Network 1'],
12 ['123.45.68.0', '123.45.68.127', 'Network 2'],
13 ['123.45.68.128', '123.45.68.255', 'Network 3']);
14
15 print "The address 123.45.68.37 is on network ".$foo->lookup("\173\105\150\45").".\n";
16 unless (defined($foo->lookup(((123*256+45)*256+65)*256+67))) {
17 print "The address 123.45.65.67 is not on a known network.\n";
18 }
19
20 print "The address 123.45.68.177 is on network ".$foo->lookup("123.45.68.177").".\n";
21
22 $foo->set_range('123.45.68.128', '123.45.68.255', 'Network 4');
23 print "The address 123.45.68.177 is now on network ".$foo->lookup("123.45.68.177").".\n";
24
26 "Array::IntSpan::IP" brings the advantages of "Array::IntSpan" to IP
27 address indices. Anywhere you use an index in "Array::IntSpan", you
28 can use an IP address in one of three forms in "Array::IntSpan::IP".
29 The three accepted forms are:
30
31 Dotted decimal
32 This is the standard human-readable format for IP addresses. The
33 conversion checks that the octets are in the range 0-255. Example:
34 '123.45.67.89'.
35
36 Network string
37 A four character string representing the octets in network order.
38 Example: "\173\105\150\131".
39
40 Integer
41 A integer value representing the IP address. Example:
42 "((123*256+45)*256+67)*256+89" or 2066563929.
43
44 Note that the algorithm has no way of distinguishing between the
45 integer values 1000 through 9999 and the network string format. It
46 will presume network string format in these instances. For instance,
47 the integer 1234 (representing the address '0.0.4.210') will be
48 interpreted as "\61\62\63\64", or the IP address '49.50.51.52'. This
49 is unavoidable since Perl does not strongly type integers and strings
50 separately and there is no other information available to distinguish
51 between the two in this situation. I do not expect that this will be a
52 problem in most situations. Most users will probably use dotted decimal
53 or network string notations, and even if they do use the integer
54 notation the likelyhood that they will be using the addresses
55 '0.0.3.232' through '0.0.39.15' as indices is relatively low.
56
58 ip_as_int
59 The class method "Array::IntSpan::IP::ip_as_int" takes as its one
60 parameter the IP address in one of the three formats mentioned above
61 and returns the integer notation.
62
64 Toby Everett, teverett@alascom.att.com
65
66
67
68perl v5.32.0 2020-07-28 Array::IntSpan::IP(3)