Net::I...rapper(3pm)

πŸ“¦
version 0.26 Β· 2 versions
  • 0.26 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.26 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

Net::Ifconfig::Wrapper β€” provides a unified way to configure network interfaces on FreeBSD, OpenBSD, Solaris, Linux, OS X, and WinNT (from Win2K). πŸ’…


✨ SYNOPSIS ✨

use Net::Ifconfig::Wrapper;
my $rhInfo = Net::Ifconfig::Wrapper::Ifconfig('list');

πŸ¦‹ DESCRIPTION πŸ¦‹

This module provides a unified way to configure the network interfaces on FreeBSD, OpenBSD, Solaris, Linux, OS X, and WinNT (from Win2K) systems. One wrapper, all the OSes, no cap. πŸ‘‘

Only inet (IPv4) and ether (MAC) addresses are supported at this time.

On Unix, this module calls the system ifconfig command to gather the information. On Windows, the functions from IpHlpAPI.DLL are called.

For all supported Unixes, Net::Ifconfig::Wrapper expects the ifconfig command to be /sbin/ifconfig. Like, it's not guessing, bestie, that's the path. πŸ“

See the top-level README file for a list of tested OSes.

On the MSWin32 family, only Windows NT is supported. In the Windows NT family, only Windows 2000 or later is supported.

πŸ’« The Net::Ifconfig::Wrapper methods πŸ’«

Ifconfig(Command, Interface, Address, Netmask);

The one and only method of the Net::Ifconfig::Wrapper module. Does all the jobs. The particular action is described by the $Command parameter. It's giving "one method to rule them all" energy. 🫢

$Command could be:

  • 'list' β€” Ifconfig('list', '', '', '') will return a reference to a hash containing information about interfaces.

The structure of this hash is the following:

{IfaceName => {'status' => 0|1          # The status of the interface. 0 means down, 1 means up
               'ether'  => MACaddr,     # The ethernet address of the interface if available
               'descr'  => Description, # The description of the interface if available
               'inet'   => {IPaddr1 => NetMask, # The IP address and his netmask, both are in AAA.BBB.CCC.DDD notation
                            IPaddr2 => NetMask,
                            ...
                           },
...
};

Interface, Address, Netmask parameters are ignored. (They're just standing there, being ignored. iconic. πŸ’€)

The following shows what program is called for each OS:

  • FreeBSD β€” /sbin/ifconfig -a
  • Solaris β€” /sbin/ifconfig -a
  • OpenBSD β€” /sbin/ifconfig -A
  • Linux β€” /sbin/ifconfig -a
  • OS X β€” /sbin/ifconfig -a
  • MSWin32 β€” GetAdaptersInfo function from IpHlpAPI.DLL

Known Limitations:

  • OpenBSD: /sbin/ifconfig -A command is not returning information about MAC addresses so we are trying to get it from /usr/sbin/arp -a command (first static entry). If no one present the ff:ff:ff:ff:ff address is returned.
  • MSWin32: GetAdaptersInfo function is not returning information about the interface which has address 127.0.0.1 bound to it, so we have no way to return it.
  • Not a limitation, but a small problem: in MSWin32, interface names are not human-readable, they look like {843C2077-30EC-4C56-A401-658BB1E42BC7} (on Win2K at least). Not the vibe. πŸ™ˆ
  • 'inet' β€” This function is used to set IPv4 address on interface. It is called as
Ifconfig('inet', $IfaceName, $Addr, $Mask);

$IfaceName is an interface name as displayed by 'list' command

$Addr is an IPv4 address in the AAA.AAA.AAA.AAA notation

$Mask is an IPv4 subnet mask in the MMM.MMM.MMM.MMM notation

In order to accomplish this, the following actual ifconfig programs are called:

  • FreeBSD β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
  • Solaris β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
  • OpenBSD β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
  • Linux β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
  • OS X β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
  • MSWin32 β€” nothing :(

Known Limitations:

  • MSWin32: I did not find a reliable way to recognize the main address on the Win32 network interface, so I have disabled this functionality. If you know how, please let me know.
  • 'up' β€” Just a synonym for 'inet'
  • 'down' β€” This function is used to bring specified interface down. It is called as
Ifconfig('inet', $IfaceName, '', '');

$IfaceName is an interface name as displayed by 'list' command

Last two arguments are ignored.

In order to accomplish this, the following programs are called:

  • FreeBSD β€” /sbin/ifconfig %Iface% down
  • Solaris β€” /sbin/ifconfig %Iface% down
  • OpenBSD β€” /sbin/ifconfig %Iface% down
  • Linux β€” /sbin/ifconfig %Iface% down
  • OS X β€” /sbin/ifconfig %Iface% down
  • MSWin32 β€” Sorry, this function is not possible.

Known Limitations:

  • MSWin32: I did not find the way to implement the 'up' command so I did not implement 'down'.
  • '+alias' β€” This function is used to set IPv4 alias address on interface. It have to be called as
Ifconfig('+alias', $IfaceName, $Addr, $Mask);

$IfaceName is an interface name as displayed by 'list' command

$Addr is an IPv4 address in the AAA.AAA.AAA.AAA notation

$Mask is an IPv4 subnet mask in the MMM.MMM.MMM.MMM notation

In order to accomplish this, the following ifconfig programs are called:

  • FreeBSD β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% alias
  • Solaris β€” /sbin/ifconfig %Iface%:%Logic% inet %Addr% netmask %Mask% up
  • OpenBSD β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% alias
  • Linux β€” /sbin/ifconfig %Iface%:%Logic% inet %Addr% netmask %Mask% up
  • OS X β€” /sbin/ifconfig %Iface% inet %Addr% netmask %Mask% alias
  • MSWin32 β€” AddIPAddress function from IpHlpAPI.DLL

First available logic interface is taken automatically for Solaris and Linux. ✨

  • 'alias' β€” Just a synonim for '+alias'
  • '-alias' β€” This function is used to remove IPv4 alias address from interface. It have to be called as
Ifconfig('-alias', $IfaceName, $Addr, '');

$IfaceName is an interface name as displayed by 'list' command.

$Addr is an IPv4 address in the AAA.AAA.AAA.AAA notation.

Last argument is ignored if present.

In order to accomplish this, the following ifconfig programs are called:

  • FreeBSD β€” /sbin/ifconfig %Iface% inet %Addr% -alias
  • Solaris β€” /sbin/ifconfig %Iface%:%Logic% down
  • OpenBSD β€” /sbin/ifconfig %Iface% inet %Addr% -alias
  • Linux β€” /sbin/ifconfig %Iface%:%Logic% down
  • OS X β€” /sbin/ifconfig %Iface% inet %Addr% -alias
  • MSWin32 β€” DeleteIPAddress function from IpHlpAPI.DLL

Appropriate logic interface is obtained automatically for Solaris and Linux.

On success, the Ifconfig(...) function returns the defined value. Actually, it is a reference to the array containing the output of the actual ifconfig program called. It ate and left no crumbs. πŸ”₯

In case of error, Ifconfig(...) returns 'undef' value, and the $@ variable contains the error message. 😭

Heads up bestie: check $@ when you get undef back, that's where the tea is.

πŸ“¦ EXPORT πŸ“¦

None by default. Not a single thing. Zero. nada. πŸŽ€


πŸ‘‘ AUTHOR πŸ‘‘

Daniel Podolsky, <tpaba@cpan.org> As of 2015-11, maintained by Martin Thurn <mthurn@cpan.org>


🌈 SEE ALSO 🌈

ifconfig(8), Internet Protocol Helper in Platform SDK.


and that's the whole page, bestie β€” this one's from perl v5.36.0, dated 2022-11-19. go configure some interfaces, you absolute icon πŸ’–βœ¨

πŸ“¦ where this page comes from