in reply to Re: Determining what NIC has an internet gateway
in thread Determining what NIC has an internet gateway
Unfortunately,
A much easier method (and avoiding shelling out) is to create an IO::Socket::INET connection and then ask it which IP it binds to:
use IO::Socket::INET; my $sock = IO::Socket::INET->new('www.google.com:80') or die "Can't bind : $@\n"; print 'IP Address with gateway to internet: ',$sock->sockhost(),"\n";
Note that this does not identify which (physical or virtual) NIC has connectivity, but then, neither does the original code, so I am not sure that that was what was actually sought. IO::Interface offers functions to make that connection.
|
|---|