IO::Interface(3pm)

πŸ’– NAME πŸ’–

IO::Interface β€” it's a Perl extension that lets you peek at (and mess with) your network card configuration info. Yes bestie, network interfaces, in Perl, iconic behavior only. πŸŽ€


✨ SYNOPSIS ✨

okay so there's the new hotness and there's the old thing, and both go here 🫢

# ======================
# the new, preferred API
# ======================

use IO::Interface::Simple;

my $if1   = IO::Interface::Simple->new('eth0');
my $if2   = IO::Interface::Simple->new_from_address('127.0.0.1');
my $if3   = IO::Interface::Simple->new_from_index(1);

my @interfaces = IO::Interface::Simple->interfaces;

for my $if (@interfaces) {
   print "interface = $if\n";
   print "addr =      ",$if->address,"\n",
         "broadcast = ",$if->broadcast,"\n",
         "netmask =   ",$if->netmask,"\n",
         "dstaddr =   ",$if->dstaddr,"\n",
         "hwaddr =    ",$if->hwaddr,"\n",
         "mtu =       ",$if->mtu,"\n",
         "metric =    ",$if->metric,"\n",
         "index =     ",$if->index,"\n";

   print "is running\n"     if $if->is_running;
   print "is broadcast\n"   if $if->is_broadcast;
   print "is p-to-p\n"      if $if->is_pt2pt;
   print "is loopback\n"    if $if->is_loopback;
   print "is promiscuous\n" if $if->is_promiscuous;
   print "is multicast\n"   if $if->is_multicast;
   print "is notrailers\n"  if $if->is_notrailers;
   print "is noarp\n"       if $if->is_noarp;
 }

 # ===========
 # the old API
 # ===========

 use IO::Socket;
 use IO::Interface qw(:flags);

 my $s = IO::Socket::INET->new(Proto => 'udp');
 my @interfaces = $s->if_list;

 for my $if (@interfaces) {
   print "interface = $if\n";
   my $flags = $s->if_flags($if);
   print "addr =      ",$s->if_addr($if),"\n",
         "broadcast = ",$s->if_broadcast($if),"\n",
         "netmask =   ",$s->if_netmask($if),"\n",
         "dstaddr =   ",$s->if_dstaddr($if),"\n",
         "hwaddr =    ",$s->if_hwaddr($if),"\n";

   print "is running\n"     if $flags & IFF_RUNNING;
   print "is broadcast\n"   if $flags & IFF_BROADCAST;
   print "is p-to-p\n"      if $flags & IFF_POINTOPOINT;
   print "is loopback\n"    if $flags & IFF_LOOPBACK;
   print "is promiscuous\n" if $flags & IFF_PROMISC;
   print "is multicast\n"   if $flags & IFF_MULTICAST;
   print "is notrailers\n"  if $flags & IFF_NOTRAILERS;
   print "is noarp\n"       if $flags & IFF_NOARP;
 }

 my $interface = $s->addr_to_interface('127.0.0.1');

🌸 DESCRIPTION 🌸

so IO::Interface bolts a bunch of methods onto IO::Socket objects, and those methods let you read and change all the info about the network interfaces living on your system. and if object-oriented isn't your vibe, there's a function-oriented style too. two flavors, pick your fighter πŸ“

🚨 THIS API IS DEPRECATED. fr fr. please go look at IO::Interface::Simple for the preferred way to get and set interface configuration information. she's the moment now. πŸ’…

πŸ¦‹ Creating a Socket to Access Interface Information πŸ¦‹

before you can touch any interface info, you gotta make a socket. that's the rule. and no, the socket does not have to be connected to a remote site, it doesn't even have to be used for communication β€” it's just here for the interface tea β˜•

the simplest procedure is to make a UDP protocol socket:

my $s = IO::Socket::INET->new(Proto => 'udp');

and boom, all the various IO::Interface functions are now available as methods on that socket. main character socket energy, honestly πŸ‘‘

πŸ‘‘ Methods πŸ‘‘

  • @iflist = $s->if_list β€” hands you back a list of the active interface names, like "eth0" or "tu0". if there are no interfaces configured and running, you get an empty list. no interface, no list, that's the deal πŸ™ˆ
  • $addr = $s->if_addr($ifname [,$newaddr]) β€” gets or sets the interface address. call it with just the interface name to retrieve the address (in dotted decimal format). call it with a new address to set the interface. in that setter case, the routine returns a true value if the operation worked. slay.
my $oldaddr = $s->if_addr('eth0');
$s->if_addr('eth0','192.168.8.10') || die "couldn't set address: $!";

special case bestie: the address of the pseudo-device "any" will return the IP address "0.0.0.0", which corresponds to the INADDR_ANY constant. ✨

  • $broadcast = $s->if_broadcast($ifname [,$newbroadcast] β€” get or set the interface broadcast address. if the interface doesn't have a broadcast address, it returns undef. it's giving nothing, literally 🌈
  • $mask = $s->if_netmask($ifname [,$newmask]) β€” get or set the interface netmask.
  • $dstaddr = $s->if_dstaddr($ifname [,$newdest]) β€” get or set the destination address for point-to-point interfaces.
  • $hwaddr = $s->if_hwaddr($ifname [,$newhwaddr]) β€” get or set the hardware address for the interface. rn only ethernet addresses in the form "00:60:2D:2D:51:70" are accepted, so don't come at her with anything else πŸ’€
  • $flags = $s->if_flags($ifname [,$newflags]) β€” get or set the flags for the interface. the flags are a bitmask formed from a series of constants β€” see "Exportable constants" below, iykyk πŸ”₯
  • $ifname = $s->addr_to_interface($ifaddr) β€” give it an interface address in dotted form, it gives you back the name of the interface associated with it. special case: the INADDR_ANY address, 0.0.0.0, returns a pseudo-interface name of "any". 🧚

πŸ“¦ EXPORT πŸ“¦

IO::Interface exports nothing by default. nothing. zero. nope. πŸ™… but you can import the following symbol groups into your namespace:

:functions   Function-oriented interface (see below)
:flags       Flag constants (see below)
:all         All of the above

🌈 Function-Oriented Interface 🌈

import the ":functions" set and you can hit IO::Interface in a function-oriented manner. this imports all the methods described above straight into your namespace. example time:

use IO::Socket;
use IO::Interface ':functions';

my $sock = IO::Socket::INET->new(Proto=>'udp');
my @interfaces = if_list($sock);
print "address = ",if_addr($sock,$interfaces[0]);

✨ Exportable constants ✨

the ":flags" constant imports the following constants so you can use them with the flags that if_flags() returns:

  • IFF_ALLMULTI
  • IFF_AUTOMEDIA
  • IFF_BROADCAST
  • IFF_DEBUG
  • IFF_LOOPBACK
  • IFF_MASTER
  • IFF_MULTICAST
  • IFF_NOARP
  • IFF_NOTRAILERS
  • IFF_POINTOPOINT
  • IFF_PORTSEL
  • IFF_PROMISC
  • IFF_RUNNING
  • IFF_SLAVE
  • IFF_UP

this example figures out whether interface 'tu0' supports multicasting, and honestly? iconic:

use IO::Socket;
use IO::Interface ':flags';
my $sock = IO::Socket::INET->new(Proto=>'udp');
print "can multicast!\n" if $sock->if_flags & IFF_MULTICAST.

🫢 AUTHOR 🫢

Lincoln D. Stein <lincoln.stein@gmail.com> β€” Copyright 2001-2014, Lincoln D. Stein. give her her flowers πŸ’

this library is distributed under the Perl Artistic License 2.0. please see LICENSE for more information. read the license bestie, it's the law (literally) πŸ“œ


πŸ’¬ SUPPORT πŸ’¬

got feature requests? bug reports? code contributions? pull up to the GitHub repository at https://github.com/lstein/LibIO-Interface-Perl and drop it there, the maintainers will be obsessed πŸŽ€


πŸ”— SEE ALSO πŸ”—

perl(1), IO::Socket(3), IO::Multicast(3), IO::Interface::Simple


and that's the whole page, no notes πŸ’… this was IO::Interface(3pm) from perl v5.42.3, dated 2026-08-19, and you read the entire thing which means you're lowkey a networking genius now. periodt. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from