NAME

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

SYNOPSIS

use Sys::HostAddr;

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

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 is IPv4 only.

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

main_ip()

main_ip will attempt to find the "main" or "primary" IP address of the machine.

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";

CAVEATS

Win32 lightly tested with Strawberry Perl 5.10.1 on Windows7 =item Win32 lacks some options, like per interface specification =item Win32 lacks some features, like timeouts during lookups =item IPv6 support not well tested.

RESTRICTIONS

IPv6 support not well tested. =item Win32 support not complete.

AUTHOR

Jeremy Kister

1 POD Error

The following errors were encountered while parsing the POD:

Around line 440:

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