Net::Ifconfig::Wrapper - provides a unified way to configure network interfaces on FreeBSD, OpenBSD, Solaris, Linux, OS X, and WinNT. |
Net::Ifconfig::Wrapper - provides a unified way to configure network interfaces on FreeBSD, OpenBSD, Solaris, Linux, OS X, and WinNT (from Win2K).
use Net::Ifconfig::Wrapper; my $rhInfo = Net::Ifconfig::Wrapper::Ifconfig('list');
This module provides a unified way to configure the network interfaces on FreeBSD, OpenBSD, Solaris, Linux, OS X, and WinNT (from Win2K) systems.
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
.
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.
Ifconfig(Command, Interface, Address, Netmask);
Net::Ifconfig::Wrapper
module. Does all the jobs.
The particular action is described by the $Command
parameter.
$Command
could be:
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.
The following shows what program is called for each OS:
/sbin/ifconfig -a
/sbin/ifconfig -a
/sbin/ifconfig -A
/sbin/ifconfig -a
/sbin/ifconfig -a
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).
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:
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up
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.
'inet'
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:
/sbin/ifconfig %Iface% down
/sbin/ifconfig %Iface% down
/sbin/ifconfig %Iface% down
/sbin/ifconfig %Iface% down
/sbin/ifconfig %Iface% down
Known Limitations:
MSWin32: I did not find the way to implement the 'up'
command so I did not implement 'down'
.
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:
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% alias
/sbin/ifconfig %Iface%:%Logic% inet %Addr% netmask %Mask% up
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% alias
/sbin/ifconfig %Iface%:%Logic% inet %Addr% netmask %Mask% up
/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% alias
AddIPAddress
function from IpHlpAPI.DLL
First available logic interface is taken automatically for Solaris and Linux
'+alias'
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:
/sbin/ifconfig %Iface% inet %Addr% -alias
/sbin/ifconfig %Iface%:%Logic% down
/sbin/ifconfig %Iface% inet %Addr% -alias
/sbin/ifconfig %Iface%:%Logic% down
/sbin/ifconfig %Iface% inet %Addr% -alias
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.
In case of error, Ifconfig(...)
returns 'undef'
value,
and the $@
variable contains the error message.
None by default.
Daniel Podolsky, <tpaba@cpan.org> As of 2015-11, maintained by Martin Thurn <mthurn@cpan.org>
ifconfig(8), Internet Protocol Helper in Platform SDK.
Net::Ifconfig::Wrapper - provides a unified way to configure network interfaces on FreeBSD, OpenBSD, Solaris, Linux, OS X, and WinNT. |