.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Sys::HostIP 3pm" .TH Sys::HostIP 3pm "2023-10-27" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Sys::HostIP \- Try extra hard to get IP address related info .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Sys::HostIP; \& \& my $hostip = Sys::HostIP\->new; \& my $ips = $hostip\->ips; \& my $interfaces = $hostip\->interfaces; .Ve .SH "DESCRIPTION" .IX Header "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, \s-1OSX,\s0 Win32, Cygwin). It does this by parsing \fBifconfig\fR\|(8) (ipconfig on Win32/Cygwin) output. .PP It has an object oriented interface and a functional one for compatibility with older versions. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .SS "ifconfig" .IX Subsection "ifconfig" .Vb 1 \& my $hostip = Sys::HostIP\->new( ifconfig => \*(Aq/path/to/your/ifconfig\*(Aq ); .Ve .PP You can set the location of ifconfig with this attribute if the code doesn't know where your ifconfig lives. .PP If you use the object oriented interface, this value is cached. .SS "if_info" .IX Subsection "if_info" The interface information. This is either created on new, or you can create it yourself at initialize. .PP .Vb 2 \& # get the cached if_info \& my $if_info = $hostip\->if_info; \& \& # create custom one at initialize \& my $hostip = Sys::HostIP\->new( if_info => {...} ); .Ve .SH "METHODS" .IX Header "METHODS" .SS "ip" .IX Subsection "ip" .Vb 1 \& my $ip = $hostip\->ip; .Ve .PP Returns a scalar containing a best guess of your host machine's \s-1IP\s0 address. On *nix (Unix, \s-1BSD,\s0 GNU/Linux, \s-1OSX,\s0 etc.) systems, it will return the loopback interface (127.0.0.1) if it can't find anything else. .SS "ips" .IX Subsection "ips" .Vb 4 \& my $all_ips = $hostip\->ips; \& foreach my $ip ( @{$all_ips} ) { \& print "IP: $ip\en"; \& } .Ve .PP Returns an array ref containing all the \s-1IP\s0 addresses of your machine. .SS "interfaces" .IX Subsection "interfaces" .Vb 1 \& my $interfaces = $hostip\->interfaces; \& \& foreach my $interface ( keys %{$interfaces} ) { \& my $ip = $interfaces\->{$interface}; \& print "$interface => $ip\en"; \& } .Ve .PP Returns a hash ref containing all pairs of interfaces and their corresponding \&\s-1IP\s0 addresses Sys::HostIP could find on your machine. .SS "\s-1EXPORT\s0" .IX Subsection "EXPORT" Nothing by default! .PP To export something explicitly, use the syntax: Nothing. .PP .Vb 2 \& use HostIP qw/ip ips interfaces/; \& # that will get you those three subroutines, for example .Ve .PP All of these subroutines will match the object oriented interface methods. .IP "\(bu" 4 ip .Sp .Vb 1 \& my $ip = ip(); .Ve .IP "\(bu" 4 ips .Sp .Vb 1 \& my $ips = ips(); .Ve .IP "\(bu" 4 interfaces .Sp .Vb 1 \& my $interfaces = interfaces(); .Ve .SH "HISTORY" .IX Header "HISTORY" Originally written by Jonathan Schatz . .PP Currently maintained by Paul Cochrane and Sawyer X . .SH "TODO" .IX Header "TODO" I haven't tested the win32 code with dialup or wireless connections. .PP Machines with output in some languages other than English fail. Neverthless, the code has been shown to work in German, Swedish, French, Italian, and Finnish locales. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) prior to 2010, Jonathan Schatz . .PP Copyright (C) 2010\-2019, Sawyer X . .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 \&\fBifconfig\fR\|(8) .IP "\(bu" 4 ipconfig