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;

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. If none found, it defaults to loopback interface.

ip

The IPv4 address of dev. If none found, it defaults to '127.0.0.1'.

ip6

The IPv6 address of dev. If none found, it defaults to '::1'.

mac

The MAC address of dev. If none found, it defaults to 'ff:ff:ff:ff:ff:ff'.

subnet

The subnet of IPv4 address ip. If none found, it defaults to '127.0.0.0/8';

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.

gatewayMac

The MAC address gatewayIp. The MAC is looked up from cache. If there is nothing in the cache, it does an ARP request to get it. Finally, if there is no response, attribute is set to undef.

target

This attribute is used when you want to detect which dev, ip, 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).

lookupMac (IPv4 address)

Will try to get the MAC address of the specified IPv4 address. First, if 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). Returns undef on failure.

debugDeviceList

Just for debugging purposes, especially on Windows systems.

AUTHOR

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Copyright (c) 2006, Patrice <GomoR> Auffret

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