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


Manual Reference Pages  -  SYS::HOSTIP (3)

.ds Aq ’

NAME

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

CONTENTS

VERSION

version 1.93

SYNOPSIS



    use Sys::HostIP;

    my $hostip     = Sys::HostIP->new;
    my $ips        = $hostip->ips;
    my $interfaces = $hostip->interfaces;



DESCRIPTION

Sys::HostIP does what it can to determine the ip address of your machine. All 3 methods work fine on every system that I’ve been able to test on. (Irix, OpenBSD, FreeBSD, NetBSD, Solaris, Linux, OSX, Win32, Cygwin). It does this by parsing ifconfig(8) (ipconfig on Win32/Cygwin) output.

It has an object oriented interface and a functional one for compatibility with older versions.

ATTRIBUTES

    ifconfig



    my $hostip = Sys::HostIP->new( ifconfig => /path/to/your/ifconfig );



You can set the location of ifconfig with this attribute if the code doesn’t know where your ifconfig lives.

If you use the object oriented interface, this value is cached.

    if_info

The interface information. This is either created on new, or you can create it yourself at initialize.



    # get the cached if_info
    my $if_info = $hostip->if_info;

    # create custom one at initialize
    my $hostip = Sys::HostIP->new( if_info => {...} );



METHODS

    ip



    my $ip = $hostip->ip;



Returns a scalar containing a best guess of your host machine’s IP address. On *nix (Unix, BSD, GNU/Linux, OSX, etc.) systems, it will return the loopback interface (127.0.0.1) if it can’t find anything else.

    ips



    my $all_ips = $hostip->ips;
    foreach my $ip ( @{$all_ips} ) {
        print "IP: $ip\n";
    }



Returns an array ref containing all the IP addresses of your machine.

    interfaces



    my $interfaces = $hostip->interfaces;

    foreach my $interface ( keys %{$interfaces} ) {
        my $ip = $interfaces->{$interface};
        print "$interface => $ip"\n";
    }



Returns a hash ref containing all pairs of interfaces and their corresponding IP addresses Sys::HostIP could find on your machine.

    EXPORT

Nothing by default!

To export something explicitly, use the syntax: Nothing.



    use HostIP qw/ip ips interfaces/;
    # that will get you those three subroutines, for example



All of these subroutines will match the object oriented interface methods.
o ip



    my $ip = ip();



o ips



    my $ips = ips();



o interfaces



    my $interfaces = interfaces();



HISTORY

Originally written by Jonathan Schatz <bluelines@divisionbyzero.com>.

Currently maintained by Sawyer X <xsawyerx@cpan.org>.

TODO

I haven’t tested the win32 code with dialup or wireless connections.

Machines with output in different languages (German, for example) fail.

SEE ALSO

o ifconfig(8)
o ipconfig

AUTHORS

o Sawyer X <xsawyerx@cpan.org>
o Jonathan Schatz <jon@divisionbyzero.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Sawyer X.

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

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


perl v5.20.3 SYS::HOSTIP (3) 2012-02-14

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