Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Cross Platform Network Interface Module

by VinsWorldcom (Parson)
on Apr 18, 2013 at 19:14 UTC ( #1029407=perlquestion: print w/replies, xml ) Need Help??
VinsWorldcom has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for a platform independent interface module to get interface information like:

  • interface name
  • device name
  • IPv4 address
  • IPv6 address
  • MAC address
  • default gateway (IPv4, IPv6 and MAC)
  • MTU
  • ...

I've found many possibilities, but all have shortcomings:

Module Issue
IO::Interface(::Simple) *nix only
Net::Interface *nix only (supposedly able to be expanded)
Win32::IPHelper Windows only and has bugs (rt://71842)
Net::Libdnet only 5 passes, ~300 other / I can't get it to compile on Windows

What do other Monks use? Or do you just backtick ifconfig / ipconfig and parse?

  • Comment on Cross Platform Network Interface Module

Replies are listed 'Best First'.
Re: Cross Platform Network Interface Module
by Corion (Pope) on Apr 18, 2013 at 19:24 UTC
    In Net::PCap::FindDevice, I spawn netstat -r to find the device IP and the default gateway. Surprisingly, the regular expression only seems to differ between Windows and "Unix", or nobodyy uses that module or complained about it. Maybe the code in that module is helpful.


      Full disclosure - I work on Windows (Win7 x64 / Stawberry 5.16.1) so already coded Win32::Interfaces to parse 'ipconfig', 'arp -a' and various 'wmic' and 'netsh' commands to get all I need. Of course, my "solution" is Windows-only and I would say not CPAN-ready due to the "parsing a system command" approach I used. Win32::IPHelper does a much better job in terms of accessing the correct Windows data structures with XS Win32::API - albeit, there are bugs and XS is a bit beyond my capabilities to fix / patch. Likewise, the *nix-centric modules I listed above use XS against the sockets API (not WinSock).

      That said, if I want to port my program (that uses Win32::Interfaces) to *nix, I'm stuffed. I could do some conditional requires based on OS, but none of the modules I've found provide all the accessors I'm looking for (IP(v6) address and gateways, MAC's, MTU, names, etc...).

        We like the idea of your Win32::Interfaces module. I see this module is not on CPAN yet. Is there a possibility that you can share this module with us?
Re: Cross Platform Network Interface Module
by hardburn (Abbot) on Apr 18, 2013 at 20:26 UTC

    I'd encourage you to code up a nice solution. You've got the perfect idea for a CPAN module here for something that doesn't appear to exist yet.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1029407]
Approved by kcott
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-05-21 11:09 GMT
Find Nodes?
    Voting Booth?