iRemix94 has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow perl users, I currently try to find a way to get information about my local network interfaces. To be more precise, I want to know which one of my network interfaces is a real (physical) or a virtual one. I don't had my eyes on the Net::Interface module, but apparently my ppm won't find the package at all. Additionally, I don't really know if the Net::Interface module can distinguish between physical and virtual network interfaces. Is there a way to get the information without the usage of that package?

Edit: For anyone interested, I found a solution:

my $dbh = DBI->connect('dbi:WMI:'); my $stmt = " SELECT Name, NetConnectionID FROM Win32_NetworkAdapter WHERE Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\\\%' "; my $sth = $dbh->prepare($stmt); $sth->execute(); while (my @row = $sth->fetchrow_array) { print "Name:\t\t\t$row[0]\Interface:\t$row[1]\n\n"; }

Replies are listed 'Best First'.
Re: Trying to get information about network interfaces
by haukex (Archbishop) on Jun 10, 2016 at 14:24 UTC

    Hi iRemix94,

    I've successfully been using IO::Interface::Simple. A quick example:

    use IO::Interface::Simple (); for my $if (IO::Interface::Simple->interfaces) { next if !$if->is_running || $if->is_loopback || !defined($if->addr +ess); print $if, "\t", $if->address, "\n"; }

    I haven't had to determine whether an interface is virtual or not, but at least these two StackOverflow answers indicate that - at least on Linux - you could determine that by looking at the files in /sys/class/net/.

    Hope this helps,
    -- Hauke D

      The script has to work on windows, so looking for files in /sys/class/net is not an option sadly. I'll try to look in the IO::Interface::Simple module though.
Re: Trying to get information about network interfaces
by Mr. Muskrat (Canon) on Jun 10, 2016 at 20:31 UTC
Re: Trying to get information about network interfaces
by stevieb (Canon) on Jun 10, 2016 at 14:15 UTC

    Hi iRemix94, can you let us know which OS you're on?

      the script has to run on windows machines.

        See also the systeminfo command output