Net::F...Device(3pm)

πŸ“¦
version 1.12 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Net::Frame::Device β€” bestie edition πŸ’–

okay so this is Net::Frame::Device, straight out of the User Contributed Perl Documentation section of your friendly neighbourhood 3pm manual set. it's giving "I need to know what my network interface is doing and I need to know NOW". let's get into it 🫢


✨ 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;

like, look at that. you literally make an object and it just tells you things. no cap πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

this module is your girl for getting network information, and it's especially useful when you're doing low-level network programming. like, when you're down there in the weeds with packets and frames and you're like "bestie which interface am I even on" β€” this is the one 🧚

it also hands you some genuinely useful functions for looking up network MAC addresses. slay πŸ’…


πŸ‘‘ ATTRIBUTES πŸ‘‘

lowkey the main event. every single one, no skips:

  • dev β€” the network device. it's 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 the default gateway that lets you access the Internet 🌈. if none found, or it's just not required in the usage context, it defaults to undef.
  • gatewayIp6 β€” the gateway IPv6 address. it defaults to the default gateway that lets you access the Internet 🌈. if none found, or it's not required in the usage context, it defaults to undef.
  • gatewayMac β€” the MAC address of gatewayIp. peep the lookupMac method for that one πŸ‘€
  • gatewayMac6 β€” the MAC address of gatewayIp6. peep the lookupMac6 method πŸ‘€
  • target β€” this attribute is what you use when you wanna detect which dev, ip, mac attributes to use for a specific target. check the SYNOPSIS.
  • target6 β€” this attribute is what you use when you wanna detect which dev, ip6, mac attributes to use for a specific target. check the SYNOPSIS again, bestie.

πŸ’œ METHODS πŸ’œ

new

new (hash)

the object constructor πŸŽ€. see SYNOPSIS for default values.

updateFromDefault

will update attributes according to the default interface that has access to the Internet. very main character of it.

updateFromDev

updateFromDev (dev)

will update attributes according to the dev attribute β€” or, if you pass dev in as a parameter, it'll use that for updating instead (and it will also set dev to this new value, so yeah, it changes on you, that's the vibe).

updateFromTarget

updateFromTarget (target)

will update attributes according to the target attribute β€” or, if you pass target in as a parameter, it'll use that for updating (and it will also set target to this new value πŸ”₯).

updateFromTarget6

updateFromTarget6 (target6)

will update attributes according to the target6 attribute β€” or, if you pass target6 in as a parameter, it'll use that for updating (and it 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. here's the whole detective arc, in order:

  1. first, it checks against the ARP cache table.
  2. then, it verifies the target is on the same subnet as we are, and if yes, it does the ARP request.
  3. if it's not on the same subnet, it tries to resolve the gateway MAC address (by using the 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 ✨). the arc goes:

  1. first, it verifies the target is on the same subnet as we are, and if yes, it does the ICMPv6 lookup request.
  2. if it's not on the same subnet, it tries to resolve the gateway MAC address (by using the 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. lowkey a lifesaver over there πŸͺŸ


πŸ’– AUTHOR πŸ’–

Patrice <GomoR> Auffret


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

you may distribute this module under the terms of the Artistic license. see the LICENSE.Artistic file in the source distribution archive πŸ“„


and that's the whole page, bestie πŸ’… one last thing: this was pulled from perl v5.38.2, dated 2024-05-04, page Net::F...Device(3pm). stan a documented module. periodt πŸ¦‹βœ¨

πŸ“¦ where this page comes from