NAME

Net::Frame::Device - get network device information and gateway

SYNOPSIS

use Net::Frame::Device;

# Get default values from system
my $device = Net::Frame::Device->new;

# Get values from a specific device
my $device2 = Net::Frame::Device->new(dev => 'vmnet1');

# Get values from a specific target
my $device3 = Net::Frame::Device->new(target => '192.168.10.2');

print "dev: ", $device->dev, "\n";
print "mac: ", $device->mac, "\n";
print "ip : ", $device->ip,  "\n";
print "ip6: ", $device->ip6, "\n";
print "gatewayIp:  ", $device->gatewayIp,  "\n" if $device->gatewayIp;
print "gatewayMac: ", $device->gatewayMac, "\n" if $device->gatewayMac;

# Get values from a specific target
my $device5 = Net::Frame::Device->new(target6 => '2001::1');

print "dev: ", $device5->dev, "\n";
print "mac: ", $device5->mac, "\n";
print "ip6: ", $device5->ip6, "\n";
print "gatewayIp6:  ", $device5->gatewayIp6, "\n" if $device5->gatewayIp6;

DESCRIPTION

This module is used to get network information, and is especially useful when you want to do low-level network programming.

It also provides useful functions to lookup network MAC addresses.

ATTRIBUTES

dev

The network device. undef if none found.

ip

The IPv4 address of dev. undef if none found.

ip6

The IPv6 address of dev. undef if none found.

mac

The MAC address of dev. undef if none found.

subnet

The subnet of IPv4 address ip. undef if none found.

subnet6

The subnet of IPv6 address ip6. undef if none found.

gatewayIp

The gateway IPv4 address. It defaults to default gateway that let you access Internet. If none found, or not required in the usage context, it defaults to undef.

gatewayIp6

The gateway IPv6 address. It defaults to default gateway that let you access Internet. If none found, or not required in the usage context, it defaults to undef.

gatewayMac

The MAC address gatewayIp. See lookupMac method.

gatewayMac6

The MAC address gatewayIp6. See lookupMac6 method.

target

This attribute is used when you want to detect which dev, ip, mac attributes to use for a specific target. See SYNOPSIS.

target6

This attribute is used when you want to detect which dev, ip6, mac attributes to use for a specific target. See SYNOPSIS.

METHODS

new
new (hash)

Object constructor. See SYNOPSIS for default values.

updateFromDefault

Will update attributes according to the default interface that has access to Internet.

updateFromDev
updateFromDev (dev)

Will update attributes according to dev attribute, or if you specify 'dev' as a parameter, it will use it for updating (and will also set dev to this new value).

updateFromTarget
updateFromTarget (target)

Will update attributes according to target attribute, or if you specify 'target' as a parameter, it will use it for updating (and will also set target to this new value).

updateFromTarget6
updateFromTarget6 (target6)

Will update attributes according to target6 attribute, or if you specify 'target6' as a parameter, it will use it for updating (and will also set target6 to this new value).

lookupMac (IPv4 address, [ retry, timeout ])

Will try to get the MAC address of the specified IPv4 address. First, it checks against ARP cache table. Then, verify the target is on the same subnet as we are, and if yes, it does the ARP request. If not on the same subnet, it tries to resolve the gateway MAC address (by using gatewayIp attribute). You can add optional parameters retry count and timeout in seconds. Returns undef on failure.

lookupMac6 (IPv6 address, [ retry, timeout ])

Will try to get the MAC address of the specified IPv6 address (using ICMPv6). First, verify the target is on the same subnet as we are, and if yes, it does the ICMPv6 lookup request. If not on the same subnet, it tries to resolve the gateway MAC address (by using gatewayIp6 attribute). You can add optional parameters retry count and timeout in seconds. Returns undef on failure.

debugDeviceList

Just for debugging purposes, especially on Windows systems.

AUTHOR

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Copyright (c) 2006-2015, Patrice <GomoR> Auffret

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.