Python Forum
Newbie seeking help with DNS query - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Newbie seeking help with DNS query (/thread-12980.html)



Newbie seeking help with DNS query - DaytonJones - Sep-21-2018

I'm fairly new to python, so I'm currently at a loss as to how to proceed...

I need to write a script that will perform a DNS query (simple, not the issue) on a hostname and then compare the results and do "something" if a change is detected (this is the problem).

Specific use case, I have an parter connection to an API endpoint, which is load-balanced and will return 3 IP's. Occasionally, those IP's will change (when the partner updates the API, when it rains, just because) and my connections will fail because I have to add the IP's to an AWS route-table (to specifically route traffic to those IP's through a NAT - don't ask)

I can easily update the route-table (delete the "old" routes, add the new") but I'm struggling at how/where to keep the current IP's and then compare the results of the query to detect if one or more have changed -- and if a change does occur, update the "current" IPs used to compare and then update the route table. The only piece I can't figure out is the IP storage/compare part... Any help appreciated.

dig +short my.api.endpoint
PsERE3uQUNuZ.gaMA7UxUguso.some-aws-region.elb.amazonaws.com
12.3.45.67
1.234.56.7
123.45.67.89