Jens Rehsack > Net-Interface-0.13_01 > Net::Interface

Download:
Net-Interface-0.13_01.tar.gz

Dependencies

Annotate this POD

Related Modules

MIME::Lite
Net::Pcap
Sys::Hostname
MIME::Types
LWP::UserAgent
Net::Telnet
IO::Socket
Inline::C
Net::Domain
more...
By perlmonks.org

CPAN RT

New  4
Open  3
View/Report Bugs
Module Version: 0.13_01   Source   Latest Release: Net-Interface-1.012

NAME ^

Net::Interface - Perl extension to access network interfaces

SYNOPSIS ^

  use Net::Interface qw(
        IFF_UP
        IFF_BROADCAST
        IFF_DEBUG
        IFF_LOOPBACK
        IFF_POINTOPOINT
        IFF_NOTRAILERS
        IFF_RUNNING
        IFF_NOARP
        IFF_PROMISC
        IFF_ALLMULTI
        IFF_MASTER
        IFF_SLAVE
        IFF_MULTICAST
        IFF_SOFTHEADERS
        IFHWADDRLEN
        IFNAMSIZ
        mac_bin2hex
  );

    or

  use Net::Interface qw(:constants mac_bin2hex);

    or for methods only

  require Net::Interface;

METHODS

  @all_ifs = Net::Interface->interfaces();

  foreach(@all_ifs) { print $_->name,"\n" };

  $if = Net::Interface->new ('eth0');

  my $name = $if->name;

  Get or Set
  $naddr = $if->address($naddr);
  $naddr = $if->broadcast($naddr);
  $naddr = $if->netmask($naddr);
  $naddr = $if->destination($naddr);
    or
  ($sa_family,$size,$naddr) = $if->address($naddr);
  ($sa_family,$size,$naddr) = $if->broadcast($naddr);
  ($sa_family,$size,$naddr) = $if->netmask($naddr);
  ($sa_family,$size,$naddr) = $if->destination($naddr);

  $mac =$if->hwaddress($hwaddr);
    or
  ($sa_family,$size,$hwaddr) = $if->hwaddress($hwaddr);

  $val = $if->flags($val);
  $val = $if->mtu ($val);
  $val = $if->metric($val);

FUNCTIONS

  $hexstring = mac_bin2hex(scalar $if->hwaddres);

DESCRIPTION ^

Net::Interface is designed to make the use of ifconfig(1) and friends unnecessary from within Perl. It provides methods to get at set all the attributes of an interface, and even create new logical or physical interfaces (if your O/S supports it).

Scalar context

The Get methods:

  $naddr = $if->address();
  $naddr = $if->broadcast();
  $naddr = $if->netmask();
  $naddr = $if->destination();

return a network address in binary form.

  $mac = $if->hwaddress();

returns a binary number which can be converted to the hex MAC address using unpack("H*",$val).

The methods:

  $val = $if->flags();
  $naddr = $if->mtu();
  $naddr = $if->metric();

return numbers or bit patterns.

Array context

The methods:

  ($sa_family,$size,$naddr) = $if->address
  ($sa_family,$size,$naddr) = $if->broadcast
  ($sa_family,$size,$naddr) = $if->netmask
  ($sa_family,$size,$naddr) = $if->destination

return a three byte array of the form:

        address family          (AF_INET, etc...)
        size of address
        address as in Scalar context above

  ($sa_family,$size,$hwaddr) = $if->hwaddress();

returns a three byte array of the form:

        address family          (AF_LOCAL)
        size of address
        binary MAC address

Set methods

Where it is supported by the OS, the methods above may be used to set a value with the syntax:

        $optional = $if->method($value);
        @optional = $if->method($value);

Functions

AUTHOR ^

  Stephen Zander <gibreel@pobox.com>

  recent updates by:
  Jerrad Pierce jpierce@cpan.org
  Michael Robinton <michael@bizsystems.com>
  Jens Rehsack <rehsack@web.de>

COPYRIGHT 1998 - 2008. All rights reserved. ^

  Stephen Zander        1998
  Jerrad Pierce         2000
  Michael Robinton      2006 - 2008
  Jens Rehsack          2008

  All rights reserved.

  Parts of the text of this README copyright 1996,1997 Graham Barr.
  All rights reserved.

  This library is free software; you can redistribute it 
  and/or modify it under the same terms as Perl itself.

SEE ALSO ^

perl(1), ifconfig(8)

syntax highlighting: