Jeremy Kister

NAME

Sys::HostAddr - Get IP address information about this host

SYNOPSIS

use Sys::HostAddr;

my $sysaddr = Sys::HostAddr->new();

my $string = $sysaddr->public();

my $aref = $sysaddr->interfaces();

my $aref = $sysaddr->addresses();

my $href = $sysaddr->ip();

my $ip = $sysaddr->first_ip();

my $main = $sysaddr->main_ip();

DESCRIPTION

Sys::HostAddr provides methods for determining IP address information about a local host.

CONSTRUCTOR

    my $sysaddr = Sys::HostAddr->new( debug     => [0|1],
                                      ipv       => [4|6],
                                      interface => 'ethX',
                                    );
debug

debug will control ancillary/informational messages being printed.

ipv

ipv will limit response data to either IPv4 or IPv6 addresses. Default: IPv4

interface

interface limits response data to a particular interface, where applicable. This value is overriden if a method is given an interface argument directly.

USAGE

public()

public will attempt to find the public ip address of your machine. usefull if you're behind some NAT. Sends an automation request to the www.dnsbyweb.com service. Works on IPv4 only.

main_ip( [$method] )

main_ip will attempt to find the "main" or "primary" IP address of the machine. method can be: auto (default), preferred (MSWin32/cygwin only), route, or dns.

first_ip( [$interface] )

first_ip will return the first ip address on a given interface (if provided), or the first ip address returned by ifconfig (that is not localhost).

ip( [$interface] )

ip will return a hash reference containing ipaddress/netmask information keyed by interface. if $interface is provded, will be limited to that interface, otherwise will include all interfaces

addresses( [$interface] )

addresses will return an array reference of all ip addresses found. if $interface is provided, will be limited to that interface.

interfaces()

interfaces will return an array reference of all interfaces found.

EXAMPLES

    use Sys::HostAddr;
    
    my $sysaddr = Sys::HostAddr->new();
    
    my $int_aref = $sysaddr->interfaces();
    foreach my $interface ( @{$int_aref} ){
        print "found $interface\n";
    }
    
    my $addr_aref = $sysaddr->addresses();
    foreach my $address ( @{$addr_aref} ){
        print "found $address\n";
    }
    
    my $href = $sysaddr->ip();
    foreach my $interface ( keys %{$href} ){
        print "$interface has: ";
        foreach my $aref ( @{$href->{$interface}} ){
             print " $aref->{addr} $aref->{netmask}\n";
        }
    }
    
    my $ip = $sysaddr->first_ip();
    print "$ip found as the first ip address\n";
    
    my $main = $sysaddr->main_ip();
    print "$main appears to be the main ip address of this machine\n";

    my $pub = $sysaddr->public();
    print "public addr appears to be $pub\n";

CAVEATS

Win32 lightly tested with Strawberry Perl 5.10.1 on Windows7
Win32 lacks some options, like per interface specification
Win32 lacks some features, like timeouts during lookups
Cygwin not tested at all, should work as well as MSWin32
IPv6 support not well tested.

RESTRICTIONS

IPv6 support not well tested.
Win32 support not complete.

AUTHOR

Jeremy Kister

1 POD Error

The following errors were encountered while parsing the POD:

Around line 471:

You forgot a '=back' before '=head1'