Display IP address along side server name in server list

This commit is contained in:
Jeffrey Forman 2012-11-26 22:05:44 -05:00
parent ba78f39670
commit 9dcb07e996
3 changed files with 33 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import dns.query
import dns.reversename
import dns.update
import dns.tsig
import socket
import re
def add_record(dns_server, zone_name, record_name, record_type, record_data, ttl, key_name, create_reverse=False):
@ -106,3 +107,20 @@ def update_record(dns_server, zone_name, record_name, record_type, record_data,
output = dns.query.tcp(dns_update, dns_server)
return output
def ip_info(host_name): # , family_dict, socket_dict):
"""Create a dictionary mapping address types to their IP's.
If an error is encountered, key to error is "Error".
"""
info = {}
try:
for s_family, s_type, s_proto, s_cannoname, s_sockaddr in socket.getaddrinfo(host_name.hostname, None):
if s_family == 2 and s_type == 1:
info["IPv4"] = s_sockaddr[0]
if s_family == 10 and s_type == 1:
info["IPv6"] = s_sockaddr[0]
except socket.gaierror, err:
info["Error"] = "Unable to resolve %s: %s" % (host_name, err)
return info

View File

@ -7,9 +7,17 @@ Server List
{% block body %}
<table class="table">
{% for current_server in server_list %}
<tr>
<td><a href="/info/{{ current_server }}/"> {{ current_server }}</td>
<th>Hostname</th>
<th>IP Address</th>
</tr>
{% for current_server in server_info %}
<tr>
<td><a href="/info/{{ current_server.host_name }}/"> {{ current_server.host_name }}</td>
<td>{% for key, value in current_server.ip_address.items %}
{{key}}: {{value}}<br>
{% endfor %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -11,8 +11,12 @@ def home_index(request):
def view_server_list(request):
""" List the DNS servers configured in the database. """
server_list = models.BindServer.objects.all().order_by("hostname")
server_info = []
for current in server_list:
server_info.append({"host_name" : current, "ip_address" : helpers.ip_info(current)})
return render(request, "bcommon/list_servers.htm",
{ "server_list" : server_list})
{ "server_info" : server_info})
def view_server_zones(request, dns_server):
""" Display the list of DNS zones a particular DNS host provides. """