Blog History

February 28, 2018

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("trunk1.freepbx.com", "A")
siptrunk2 = resolve1.query("trunk2.freepbx.com", "A") 
for results1 in siptrunk1:
    str1 = str(results1)
    print("TRUNK1 IP address is "+ str1 + "....")
    if (str1 == "192.159.66.3"):
        print ("....all is quiet, TRUNK1 is still 192.159.66.3")
    else:
        print ("....TRUNK1 is no longer 192.159.66.3!") 
print("") 
for results2 in siptrunk2:
    str2 = str(results2)
    print("TRUNK2 IP address is "+ str2 + "....")
    if (str2 == "162.253.134.142"):
        print ("....all is quiet, TRUNK2 is still 162.253.134.142")
    else:
        print ("....TRUNK2 is no longer 162.253.134.142!")
print("") 
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