dhcp.cgi: Add column with resolved hostname by IP address
Commit Message
In web interface, on page DHCP Server, in table Current fixed leases, add column with resolved hostname by IP address
---
html/cgi-bin/dhcp.cgi | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
Comments
Hello Sebastien,
and thank you for this patch. Looks good to me; it will land in Core
Update 182. Keep these coming, appreciated! :-)
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
Thanks, and best regards,
Peter Müller
> In web interface, on page DHCP Server, in table Current fixed leases, add column with resolved hostname by IP address
> ---
> html/cgi-bin/dhcp.cgi | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi
> index f45703f0b..b87da6907 100755
> --- a/html/cgi-bin/dhcp.cgi
> +++ b/html/cgi-bin/dhcp.cgi
> @@ -21,6 +21,7 @@
>
> use strict;
> use experimental 'smartmatch';
> +use IO::Socket;
>
> # enable only the following on debugging purpose
> #use warnings;
> @@ -1007,8 +1008,9 @@ END
> print <<END
> <table width='100%' class='tbl'>
> <tr>
> - <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
> - <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
> + <th width='15%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
> + <th width='10%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
> + <th width='15%' align='center'><b>$Lang::tr{'hostname'}</b></th>
> <th width='15%' align='center'><b>$Lang::tr{'remark'}</b></th>
> <th width='15%' class='boldbase' align='center'><b>next-server</b></th>
> <th width='15%' class='boldbase' align='center'><b>filename</b></th>
> @@ -1106,9 +1108,14 @@ foreach my $line (@current2) {
> $TAG4 = "class='red'" if ($dhcpsettings{'KEY2'} ne $key);
> }
>
> + # resolved name (if exists)
> + my $iaddr = inet_aton($temp[1]);
> + my $rname = gethostbyaddr($iaddr, AF_INET);
> + if (!$rname || $rname eq "") { $rname = $Lang::tr{'ptr lookup failed'}; }
> print <<END
> <td align='center' $col>$TAG2$temp[0]$TAG3</td>
> <td align='center' $TAG4 $col>$TAG0$temp[1]$TAG1</td>
> +<td align='center' $col>$rname </td>
> <td align='center' $col>$temp[6] </td>
> <td align='center' $col>$temp[3] </td>
> <td align='center' $col>$temp[4] </td>
@@ -21,6 +21,7 @@
use strict;
use experimental 'smartmatch';
+use IO::Socket;
# enable only the following on debugging purpose
#use warnings;
@@ -1007,8 +1008,9 @@ END
print <<END
<table width='100%' class='tbl'>
<tr>
- <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
- <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
+ <th width='15%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
+ <th width='10%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
+ <th width='15%' align='center'><b>$Lang::tr{'hostname'}</b></th>
<th width='15%' align='center'><b>$Lang::tr{'remark'}</b></th>
<th width='15%' class='boldbase' align='center'><b>next-server</b></th>
<th width='15%' class='boldbase' align='center'><b>filename</b></th>
@@ -1106,9 +1108,14 @@ foreach my $line (@current2) {
$TAG4 = "class='red'" if ($dhcpsettings{'KEY2'} ne $key);
}
+ # resolved name (if exists)
+ my $iaddr = inet_aton($temp[1]);
+ my $rname = gethostbyaddr($iaddr, AF_INET);
+ if (!$rname || $rname eq "") { $rname = $Lang::tr{'ptr lookup failed'}; }
print <<END
<td align='center' $col>$TAG2$temp[0]$TAG3</td>
<td align='center' $TAG4 $col>$TAG0$temp[1]$TAG1</td>
+<td align='center' $col>$rname </td>
<td align='center' $col>$temp[6] </td>
<td align='center' $col>$temp[3] </td>
<td align='center' $col>$temp[4] </td>