Periodically pings a list of configured DNS names, checking each for an IP address reassignment. Emails the before and after IP addresses to an interested party when a target DNS name's IP address changes. All files reside in a single flat directory.
Governed by a template in props.py
. It should work unchanged. You could alter it to suit
after you see the script operate for you.
From: IP Checker <ipchecker@hostsite.org>
To: Interested Party <sombody@somesite.org>
Subject: www.somesite.com IP Tracking
DNS name | www.somesite.com |
---|---|
IP Change | True |
Current IP | 207.142.140.32 |
Cached IP | 207.142.140.107 |
From DNS IP Checker
Copyright (c) 2013 Louis E. Mauget, mauget@mindspring.com
Linux, Mac OS, Microsoft Windows, ... any platform where a Python 2.7.2, or greater is available. This includes Python 3 versions.
- Copy the
*.py
files to your desired installation directory - Rename
props_template.py
toprops.py
- Edit the values of
props.py
for your environment and the desired behavior_ chmod 755 *.py
(unless installed on Microsoft Windows)
Important: the script cannot operate rationally for you unless you edit the values in step 3.
Microsoft Windows has no default Python system installed. Choose and download a Python for Microsoft Windows from http://www.python.org/getit/windows/.
In the installation directory use .\ipchecker.py
. If using Microsoft Windows
issue ./ipchecker.py
or invoke python ipchecker.py
.
If props.do_run = True
, then the checking process will happen forever at intervals
defined by the number of seconds in props.interval
. For example props.interval = 30*60
will cause the process to carry out its check once per half hour._
The script records a trace of its operation in a log file.
Logging level and log file name are controlled by logging_level
and logging_file
values in props.py
.
Example of logging file content:
INFO:2013-05-12 09:05:05 PM ipchecker started
INFO:2013-05-12 09:05:05 PM Resolved "google.com". Current IP "74.125.228.102". Cached IP "74.125.228.100"
INFO:2013-05-12 09:05:06 PM Successfully sent email
We tried to make the configuration keys/names self-explanatory. Don't change the name on the left side of the equal sign. Do set the value as desired.
dns_name = ['google.com']
interval = 60*30
Value can be True
or False
. Case matters.
do_run = True
Value can be True
or False
. Case matters.
always_notify = True
Get most of these from your email provider. Exception: the smtp_debug_level
enables dumping extra information to stdout
if set to non-zero.
smtp_server = 'smtp.embarqmail.com
smtp_port = 587
smtp_user = 'someUserName'
smtp_debug_level = 1; # 1 or 0 works
smtp_password = 'password'
A comma-separated series of email recipient addresses enclosed in square brackets. Each address is surrounded by single or double quotes. You probably will use just one recipient, but this example shows how to specify a distribution list.
receivers = ['receiver1@somesite.com', 'receiver2@otherplace.org']
There are five '%s' substitution points in the message. Top to bottom, these take the respective values of:
sender
-- sending email address configured abovedns_name
- target DNS name-of-interest configured abovedns_name
- target DNS name-of-interest configured above- is_changed - value True or False - calculated
- revolved IP address of
dns_name
- queried - cached previous IP address of
dns_name
- read from configured tracking file
message_template = """From: DNS Tracker<%s>
To: Lou Mauget<mauget@mindspring.com>
MIME-Version: 1.0
Content-type: text/html
Subject: %s IP Tracking
<table>
<tr><th>DNS name</th><td>%s</td></tr>
<tr><th>IP Change</th><td>%s</td></tr>
<tr><th>Current IP</th><td>%s</td></tr>
<tr><th>Cached IP</th><td>%s</td></tr>
</table>
<p>
From DNS IP Checker
</p>
"""
tracker_file = 'tracker_file.txt'
Valid logging level value is choice of:
- logging.INFO
- logging.WARN
- logging.DEBUG
- logging.ERROR
- logging.CRITICAL
logging_level = logging.INFO
logging_file = 'ipchecker.log'
Lou Mauget, mauget@gmail.com, 2020-10-15