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
NetAddr::IP::Find(3) User Contributed Perl Documentation NetAddr::IP::Find(3)

NetAddr::IP::Find - Find IP addresses in plain text

  use NetAddr::IP::Find;
  $num_found = find_ipaddrs($text, \&callback);

This is a module for finding IP addresses in plain text.

NetAddr::IP::Find exports one function, find_ipaddrs(). It works very similar to URI::Find's find_uris() or Email::Find's find_emails().

  $num_ipaddrs_found = find_ipaddrs($text, \&callback);

The first argument is a text to search through and manipulate. Second is a callback routine which defines what to do with each IP address as they're found. It returns the total number of IP addresses found.

The callback is given two arguments. The first is a NetAddr::IP instance representing the IP address found. The second is the actual IP address as found in the text. Whatever the callback returns will replace the original text.

  # For each IP address found, ping its host to see if its alive.
  use Net::Ping;
  my $pinger = Net::Ping->new;
  my %pinged;
  find_ipaddrs($text, sub {
                   my($ipaddr, $orig) = @_;
                   my $host = $ipaddr->to_string;
                   next if exists $pinged{$host};
                   $pinged{$host} = $pinger->ping($host);
               });

  while (my($host, $up) == each %pinged) {
      print "$host is " . $up ? 'up' : 'down' . "\n";
  }


  # Resolve IP address to FQDN
  find_ipaddrs($text, sub {
                   my($ipaddr, $orig) = @_;
                   resolve_ip($ipaddr->to_string);
               });

  sub resolve_ip {
      use Net::DNS;
      # see perldoc Net::DNS for details
  }

  • Subnet support.
  • IPv6 support.

Tatsuhiko Miyagawa <miyagawa@bulknews.net>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

NetAddr::IP, URI::Find, Email::Find, jdresove
2003-07-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

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