use warnings; use strict; use Data::Dumper; use Net::Libdnet; my $addr; # IP address my $interf_ref; # hash reference to the NIC interface structure my %interf_hash; # hash with the interface structure referenced as $interf_ref $addr = '10.100.20.1'; # gateway IP addr $interf_ref = Net::Libdnet::intf_get_dst($addr); # Net::Libdnet::intf_get_dst() -- retrieves the configuration for the best interface with which to reach the specified destination IP address print Data::Dumper->Dump([\$interf_ref], [qw(interface)]); $addr = '10.100.20.69'; # my IP addr $interf_ref = Net::Libdnet::intf_get_src($addr); # Net::Libdnet::intf_get_src() -- retrieves the configuration for the interface with the specified source IP address. print Data::Dumper->Dump([\$interf_ref], [qw(interface)]); $interf_ref = Net::Libdnet::intf_get('eth0'); # Net::Libdnet::intf_get() -- retrieves an interface configuration entry, keyed on name %interf_hash = %{$interf_ref}; print Data::Dumper->Dump([\%interf_hash], [qw(interface_eth0)]); print "Key value: ", $interf_hash{'mtu'}, "\n"; print "Key value: ", ${$interf_ref}{'link_addr'}, "\n"; $interf_ref = Net::Libdnet::intf_get('eth1'); print Data::Dumper->Dump([\$interf_ref], [qw(interface_eth1)]); $interf_ref = Net::Libdnet::intf_get('eth2'); print Data::Dumper->Dump([\$interf_ref], [qw(interface_eth2)]); system('pause'); exit(0);