Skip to content

Instantly share code, notes, and snippets.

@specialcircumstances
Created March 25, 2020 17:35
Show Gist options
  • Save specialcircumstances/f88e90867747b6c53dc45111fc764c76 to your computer and use it in GitHub Desktop.
Save specialcircumstances/f88e90867747b6c53dc45111fc764c76 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# gathers GSLB statistics for a particular name
from __future__ import print_function
from time import sleep
import curses
import dns.name
import dns.query
import dns.resolver
hostname = 'myglobalname.domain.com'
stdscr = curses.initscr()
qname = dns.name.from_text(hostname)
def main(stdscr):
stats = {}
while True:
answers = dns.resolver.query(qname, 'A')
ipaddr = str(answers[0])
if ipaddr in stats.keys():
stats[ipaddr] += 1
else:
stats[ipaddr] = 1
total = 0
for ipaddr, count in stats.items():
total += count
stdscr.clear()
stdscr.addstr(1,3,"Testing resolution for %s" % hostname)
stdscr.addstr(3,3,"IP Address")
stdscr.addstr(3,21,"Count")
stdscr.addstr(3,30,"Percentage")
i = 4
for ipaddr, count in stats.items():
stdscr.addstr(i,3,ipaddr)
stdscr.addstr(i,21,repr(count))
stdscr.addstr(i,30,"%d%%" % (count*100/total))
i += 1
stdscr.refresh()
sleep(5)
curses.wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment