The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Sys::HostIP - Try extra hard to get ip address related info

SYNOPSIS

use Sys::HostIP; 

my $ip_address = Sys::HostIP->ip; 
# $ip_address is a scalar containing a best guess of your host machines ip
# address. It will return loopback (127.0.0.1) if it can't find anything else.

my $ip_addresses = Sys::HostIP->ips; 
# $ip_addresses is an array ref containing all the ip addresses of your
# machine 

my $interfaces = Sys::HostIP->interfaces;
# $interfaces is a hash ref containg all pairs of interfaces/ip addresses
# Sys::HostIP could find on your machine.

DESCRIPTION

Sys::HostIP does what it can to determine the ip address of your machine. All 3 methods work fine on every *nix that I've been able to test on. (Irix, OpenBSD, FreeBSD, NetBSD, Solaris, Linux, OSX) Unfortunately, I have no access to a Win32 machine, so this code is leftover from the old (1.0) version of this code (which i did not write) and thus, only the ip() method is trully implemented (*hint* patches are welcome).

EXPORT

Nothing, because I wrote this as a class. Classes are so much easier on the eyes when reading other's code, don't you think?

AUTHOR

Jonathan Schatz <bluelines@divisionbyzero.com>

TODO

Rewrite this via XS and ifaddrlist from Net::RawIP (although this will ruin portability to non-*nix systems).

SEE ALSO

ifconfig(8)

perl.