++ed by:
ILUX

1 PAUSE user

Michael Vincent
and 1 contributors

NAME

Win32::Net::Info - Win32 Network Adapter Interface

SYNOPSIS

  use Win32::Net::Info;

  my $interface = Win32::Net::Info->new('Wireless Network Connection');

  printf "Name: %s\n", $interface->name;
  printf "MAC: %s\n", $interface->mac;
  printf "IPv4: %s\n", $interface->ipv4;

DESCRIPTION

Win32::Net::Info is a module to retrieve Windows interface adapter information (such as IP[v6] addresses, gateways, MAC, etc...). It is implemented with system functions such as wmic, netsh and arp. A better approach may be to use XS with GetAdaptersAddresses() and parse the IP_ADAPTER_ADDRESSES structure. Alas, that is proving difficult to do.

This module was developed since I couldn't find an existing CPAN module that handled this information specifically for Windows, let alone find Win32 support in the many interface modules already on CPAN (see SEE ALSO). The existing CPAN interface modules also used different APIs so finding a common interface for both Windows and *nix with all the features was not possible.

This modules attempts to provide many of the API calls from *nix interface modules specifically to Win32.

METHODS

new() - create a new Win32::Net::Info object

  my $interfaces = Win32::Net::Info->new([OPTIONS]);

Create a new Win32::Net::Info object with OPTIONS as optional parameters. Valid options are:

  Option      Description                           Default
  ------      -----------                           -------
  -interface  Friendly name of interface            Local Area Connection
  -dev
  -device

Called with option eliminates the need to call the interface() method.

Single option indicates interface.

interface() - find provided interface

  my $interface = $interfaces->interface(OPTIONS);

Find provided interface and populate the return object. Valid options are:

  Option      Description                           Default
  ------      -----------                           -------
  -interface  Friendly name of interface            [none]
  -dev
  -device

Single option indicates interface.

Allows the following to be called.

name() - return name of interface

  $interface->name();

Return friendly name of interface. This in in the form of 'Local Area Connection', for example.

adaptername() - return adapter name of interface

  $interface->adaptername();

Return adapter name of interface. This is in the form of '{1234ABCD-12AB-34CD-56EF-123456ABCDEF}', for example.

hostname() - return host name of interface

  $interface->hostname();

Return host name of interface.

Alias:

host

domainname() - return domain name of interface

  $interface->domainname();

Return domain name of interface.

Alias:

domain

devicename() - return device name of interface

  $interface->devicename();

Return adapter name of interface. This is in the form of '\Device\NPF_{1234ABCD-12AB-34CD-56EF-123456ABCDEF}', for example. Optional argument drops the PCap prefix (default '\Device\NPF_').

Alias:

dev
device

description() - return description of interface

  $interface->description();

Return description of interface.

ifindex() - return ifIndex of interface

  $interface->ifindex();

Return interface index of interface.

Alias:

index

mac() - return MAC address of interface

  $interface->mac();

Return MAC address of interface.

ipv4() - return IPv4 address of interface

  [$ret | @ret =] $interface->ipv4();

Return IPv4 address of interface. Scalar context returns first, array context returns all.

Alias:

ip

ipv4_netmask() - return IPv4 network mask of interface

  [$ret | @ret =] $interface->ipv4_netmask();

Return IPv4 network mask of interface. Scalar context returns first, array context returns all.

Alias:

netmaskIp

ipv6() - return IPv6 address of interface

  [$ret | @ret =] $interface->ipv6();

Return IPv6 address of interface. Scalar context returns first, array context returns all.

Alias:

ip6

ipv6_netmask() - return IPv6 network mask of interface

  [$ret | @ret =] $interface->ipv6_netmask();

Return IPv6 network mask of interface. Scalar context returns first, array context returns all.

Alias:

netmaskIp6
  [$ret | @ret =] $interface->ipv6_link_local();

Return IPv6 link-local address of interface. Scalar context returns first, array context returns all.

  [$ret | @ret =] $interface->ipv6_link_local_netmask();

Return IPv6 link local network mask of interface. Scalar context returns first, array context returns all.

ipv4_default_gateway() - return IPv4 default gateway of interface

  [$ret | @ret =] $interface->ipv4_default_gateway();

Return IPv4 default gateway of interface. Scalar context returns first, array context returns all.

Alias:

gatewayIp

ipv4_gateway_metric() - return IPv4 gateway metric of interface

  [$ret | @ret =] $interface->ipv4_gateway_metric();

Return IPv4 gateway metric of interface. Scalar context returns first, array context returns all.

Alias:

metric

ipv6_default_gateway() - return IPv6 default gateway of interface

  [$ret | @ret =] $interface->ipv6_default_gateway();

Return IPv6 default gateway of interface. Scalar context returns first, array context returns all.

Alias:

gatewayIp6

ipv6_gateway_metric() - return IPv6 gateway metric of interface

  [$ret | @ret =] $interface->ipv6_gateway_metric();

Return IPv6 gateway metric of interface. Scalar context returns first, array context returns all.

Alias:

metric6

ipv4_gateway_mac() - return MAC address of IPv4 default gateway of interface

  $interface->ipv4_gateway_mac();

Return MAC address of IPv4 default gateway of interface.

Alias:

gatewayMac

ipv6_gateway_mac() - return MAC address of IPv6 default gateway of interface

  $interface->ipv6_gateway_mac();

Return MAC address of IPv6 default gateway of interface.

Alias:

gatewayMac6

ipv4_mtu() - return MTU of interface for IPv4

  $interface->ipv4_mtu();

Return MTU of interface for IPv4.

ipv6_mtu() - return MTU of interface for IPv6

  $interface->ipv6_mtu();

Return MTU of interface for IPv6.

mtu() - return MTU of interface

  $interface->mtu();

Return MTU of interface. Minimum value between IPv4 and IPv6 MTU if both exist; otherwise, just the value of the MTU that does exist. Undef if neither exist.

ipv4_dns_server() - return IPv4 DNS servers of interface

  [$ret | @ret =] $interface->ipv4_dns_server();

Return IPv4 DNS servers of interface. Scalar context returns first, array context returns all.

Alias:

dnsserver

ipv6_dns_server() - return IPv6 DNS servers of interface

  [$ret | @ret =] $interface->ipv6_dns_server();

Return IPv6 DNS servers of interface. Scalar context returns first, array context returns all.

Alias:

dnsserver6

dump() - dump interface information

  $interface->dump;

Dump all interface information (basically, all of the above).

Alias:

info

pcap_prefix() - get or set pcap prefix

  $interface->pcap_prefix([name]);

Return the PCap prefix (default '\Device\NPF_'). Optional name sets the PCap prefix for future calls to adaptername.

error() - print last error

  printf "Error: %s\n", Win32::Net::Info->error;

Return last error.

SUBROUTINES

interfaces() - list available interfaces

  my $interfaces = Win32::Net::Info->interfaces;

List available interfaces by friendly name.

  Context   Usage                                Return
  -------   -----                                ------
  none      Win32::Net::Info->interfaces;       (print list)
  SCALAR    $i = Win32::Net::Info->interfaces;  array ref
  ARRAY     @i = Win32::Net::Info->interfaces;  array

lookupMac() - lookup IPv4 address MAC address

  my $mac = Win32::Net::Info->lookupMac(ipv4_addr);

Return MAC address for provided IPv4 address.

lookupMac6() - lookup IPv6 address MAC address

  my $mac = Win32::Net::Info->lookupMac6(ipv6_addr);

Return MAC address for provided IPv6 address.

EXPORTS

Load them: use Win32::Net::Info qw(:subs):

interfaces
lookupMac
lookupMac6

SEE ALSO

IO::Interface, Net::Interface, Win32::IPHelper, Win32::IPConfig, Net::Libdnet

LICENSE

This software is released under the same terms as Perl itself. If you don't know what that means visit http://perl.com/.

AUTHOR

Copyright (c) 2011 Michael Vincent

http://www.VinsWorld.com

All rights reserved