Search for previous posts

Blog History


Scheduled Python FQDN checker

I needed to restrict SIP ports to the FQDNs of SipStation's gateways, but unfortunately Unifi still hasn't updated there port forwarding/firewall to restrict via FQDN so I had to use an IP address. But SipStation occasionally changes their IP though, so I needed a way to monitor this change to adjust my firewall. I hope Unifi updates the USG soon, but in the meantime, this is what I created.

Here is my Python script:
import dns.resolver
resolve1 = dns.resolver.Resolver()
siptrunk1 = resolve1.query("", "A")
siptrunk2 = resolve1.query("", "A") 
for results1 in siptrunk1:
    str1 = str(results1)
    print("TRUNK1 IP address is "+ str1 + "....")
    if (str1 == ""):
        print ("....all is quiet, TRUNK1 is still")
        print ("....TRUNK1 is no longer!") 
for results2 in siptrunk2:
    str2 = str(results2)
    print("TRUNK2 IP address is "+ str2 + "....")
    if (str2 == ""):
        print ("....all is quiet, TRUNK2 is still")
        print ("....TRUNK2 is no longer!")
input("Press enter to exit")
Then I created a simple batch file that I then put on a Windows scheduled task to run everyday. Crude, but it works.

No comments:

Post a Comment