To automate the process of checking Dyn DNS status and sending updates to specific channels, you can use a Python script that sends emails with links to online web-based tools like Dyn DNS itself or other similar services (e.g., IPCHANGER). Below is an example script that accomplishes this:
``
python
import requests
import socket
from email import MIMEMessage
def check_dyn_dns(url):
try:
response = requests.head(url)
return True if 'Status: NO CHANGE' in str(response.text) else False
except requests.exceptions.RequestException as e:
print(f"Error fetching {url}: {e}")
return True
def send_update_email(target, message=''):
msg = MIMEMessage()
msg['Subject'] = f"DynDNS {target} Status: {status}"
msg['From'] = 'your-email@hermes.bot'
msg['To'] = target
msg.set_content(message)
with open('dyndns-reminder.txt', 'r') as file:
content = file.read()
if status != "Status:NO_CHANGE":
url = f"http://www.dynamindedns.io/{target}/status"
response = requests.head(url)
msg_body = MIMEBody(content, 'text/plain')
with open('dyndns-text.txt', 'r') as file:
message_lines = [line.strip() for line in file.readlines()]
if len(message_lines) > 0 and not url.startswith(message_lines[0]):
content_url = "http://www.dynamindedns.io/" + message_lines[0] + "/status"
try:
open(content_url, 'w').close()
msg_body.add_header('Content-Disposition', f'attachment; filename="dyndns.txt"$')
print(f"Sending update to {target}: {status}")
msg.attach(MIMEText(msg_body.as_string(), 'plain'))
smtp_host, smtp_port = 'smtp.example.com', 587
smtp_username = 'your-smtp-username'
smtp_password = 'your-password'
try:
server = smtplib.SMTP(smtp_host, smtp_port)
server.starttls()
server.login(smtp_username, smtp_password)
server.sendmail(smtp_username, target, msg.as_string())
server.quit()
print(f"Update sent to {target}: OK")
except Exception as e:
print(f"Error sending update to {target}: {e}")
def main():
url = "example.com"
status = True
send_update_email(url, check_dyn_dns(url))
if __name__ == "__main__":
main()
`
Replace 'your-smtp-username'
and 'your-password'
with your actual SMTP login credentials.
Remember to change the url
in the main()` function accordingly for each Dyn DNS domain you wish to check.
**Important Note:** Always ensure that any email server or application handling such emails have the necessary permissions and access controls to send on behalf of the script running as it is a scheduled task, not an individual executing the script manually. This is a general guideline when utilizing automation scripts across your cluster (on Herme, etc.).