App-DHCPClientUtils
view release on metacpan or search on metacpan
scripts/network-interface-info.pl view on Meta::CPAN
print "interface = $if\n========================\n";
my $hwaddr = join(':', (length($info->{mac}) ? unpack('H*', $info->{mac}) : '') =~ m/../g);
$hwaddr = "none" if (!$hwaddr);
printf("hwaddr = %s\n", $hwaddr);
# Query DHCP-information (if any is available)
my $dhclient = Net::ISC::DHCPClient->new(
leases_path => \@paths_to_attempt,
interface => $if->{name},
af => ['inet', 'inet6']
);
# IPv4
my $ipv4_addrs = $info->{Net::Interface->af_inet()}->{number};
$ipv4_addrs = 0 if (!$ipv4_addrs);
printf("IPv4 addrs = %d\n", $ipv4_addrs);
my @v4addresses = $if->address(Net::Interface->af_inet());
my @v6addresses = $if->address(Net::Interface->af_inet6());
print " addr = ", Net::Interface::inet_ntoa($v4addresses[0]), "\n",
" broadcast = ", Net::Interface::inet_ntoa($if->broadcast(Net::Interface->af_inet())), "\n",
" netmask = ", Net::Interface::inet_ntoa($if->netmask(Net::Interface->af_inet())), "\n";
if ($dhclient->is_dhcp('inet')) {
my $lease = @{$dhclient->leases_af_inet()}[0];
print " gateway = ", $lease->option()->{routers}, " (from DHCP)\n";
}
print "IPv4 flags:\n";
print " is running\n" if $flags & IFF_RUNNING;
scripts/network-interface-info.pl view on Meta::CPAN
my $lease = @{$dhclient->leases_af_inet()}[0];
if ($lease->expire >= $now) {
printf("lease will expire at: %s\n",
POSIX::strftime("%F %X", localtime($lease->expire)));
} else {
print("lease is expired\n");
}
}
# IPv6
my $ipv6_addrs = $info->{Net::Interface->af_inet6()}->{number};
$ipv6_addrs = 0 if (!$ipv6_addrs);
printf("IPv6 addrs = %d\n", $ipv6_addrs);
my $addrNro = 0;
foreach my $ip (@v6addresses) {
++$addrNro;
my $prefix = unpack('%B128', $if->netmask(Net::Interface->af_inet6()));
my $scope = '-something-unknown-';
$scope = RFC2373_NODELOCAL if ($if->scope() == 0x1);
$scope = RFC2373_LINKLOCAL if ($if->scope() == 0x2);
$scope = RFC2373_SITELOCAL if ($if->scope() == 0x5);
$scope = RFC2373_ORGLOCAL if ($if->scope() == 0x8);
$scope = RFC2373_GLOBAL if ($if->scope() == 0xe);
my @types = ();
push(@types, "any") if (type($ip) & IPV6_ADDR_ANY);
push(@types, "unicast") if (type($ip) & IPV6_ADDR_UNICAST);
scripts/network-interface-info.pl view on Meta::CPAN
push(@types, "teredo") if (type($ip) & IPV6_ADDR_TEREDO);
push(@types, "orchid") if (type($ip) & IPV6_ADDR_ORCHID);
push(@types, "non-routeable-doc") if (type($ip) & IPV6_ADDR_NON_ROUTE_DOC);
printf(" %d: addr = %s/%s\n scope = %s\n type = %s\n",
$addrNro,
ipV6compress(full_inet_ntop($ip)), $prefix,
$scope, join(', ', @types)
);
}
if ($dhclient->is_dhcp('inet6')) {
print " is DHCP, ";
my $now = time();
my $lease = @{$dhclient->leases_af_inet6()}[0];
my $starts = $lease->starts('non-temporary');
my $max_life = $lease->max_life('non-temporary');
if ($starts + $max_life >= $now) {
printf("lease will expire at: %s,\n now is: %s\n",
POSIX::strftime("%F %H:%M:%S", localtime($starts + $max_life)),
POSIX::strftime("%F %H:%M:%S", localtime($now))
);
} else {
print("lease is expired\n");
}
( run in 0.270 second using v1.01-cache-2.11-cpan-87723dcf8b7 )