Skip to content

Instantly share code, notes, and snippets.

Last active July 5, 2020 17:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simple script that will monitor a list of names and make sure the IPs match. Useful if you not using CNAMES for APEX domains. Output can be put on a web server and monitored for status.
#!/usr/bin/env python3
import socket
import datetime
domainlist = {
'': '',
'': ''
statusdetail = []
serviceOK = True
for domain in domainlist:
siteip = socket.gethostbyname_ex(domain)[2]
refip = socket.gethostbyname_ex(domainlist[domain])[2]
siteip = ' '.join(siteip)
refip = ' '.join(refip)
if siteip == refip:
statusdetail.append(f"""<div id="status" class="ok">{domain} ({siteip}): OK</div><br>""")
statusdetail.append(f"""<div id="status" class="error">{domain} ({siteip}): ERROR new IP - {refip}</div><br>""")
serviceOK = False
<title>Monitor IP</title>
#status.ok {{color: green;}}
#status.error {{color: red;}}
<h1>Service Status: {status}</h1>
<div>Updated: {datestamp}</div>
status = serviceOK,
detail = "\n".join(statusdetail),
datestamp =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment