in reply to Determining what NIC has an internet gateway
I use the following code/logic in Net::Pcap::FindDevice to find the interface with the default gateway:
# `netstat -rn` my $device_ip; my $re_if = $^O eq 'MSWin32' ? qr/^\s*(?:0.0.0.0)\s+(\S+)\s+(\S+)\s+/ : qr/^(?:0.0.0.0|default)\s+(\S+)\s+.*?(\S+)\s*$/; for (qx{netstat -rn}) { if ( /$re_if/ ) { $device_ip = $2; last; }; };
This gives me the IP address of the device. After that, it's just a matter of finding the corresponding Net::Pcap device, but that's of little oncernt to you :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determining what NIC has an internet gateway
by idsfa (Vicar) on Feb 18, 2006 at 22:54 UTC |