Display IP address along side server name in server list
This commit is contained in:
parent
ba78f39670
commit
9dcb07e996
|
@ -4,6 +4,7 @@ import dns.query
|
||||||
import dns.reversename
|
import dns.reversename
|
||||||
import dns.update
|
import dns.update
|
||||||
import dns.tsig
|
import dns.tsig
|
||||||
|
import socket
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def add_record(dns_server, zone_name, record_name, record_type, record_data, ttl, key_name, create_reverse=False):
|
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)
|
output = dns.query.tcp(dns_update, dns_server)
|
||||||
|
|
||||||
return output
|
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
|
||||||
|
|
|
@ -7,9 +7,17 @@ Server List
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
{% for current_server in server_list %}
|
|
||||||
<tr>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -11,8 +11,12 @@ def home_index(request):
|
||||||
def view_server_list(request):
|
def view_server_list(request):
|
||||||
""" List the DNS servers configured in the database. """
|
""" List the DNS servers configured in the database. """
|
||||||
server_list = models.BindServer.objects.all().order_by("hostname")
|
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",
|
return render(request, "bcommon/list_servers.htm",
|
||||||
{ "server_list" : server_list})
|
{ "server_info" : server_info})
|
||||||
|
|
||||||
def view_server_zones(request, dns_server):
|
def view_server_zones(request, dns_server):
|
||||||
""" Display the list of DNS zones a particular DNS host provides. """
|
""" Display the list of DNS zones a particular DNS host provides. """
|
||||||
|
|
Loading…
Reference in New Issue