-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoIP_updater.py
30 lines (26 loc) · 902 Bytes
/
noIP_updater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 14 16:05:54 2022
@author: panna
"""
import logging
from requests import get
import time
last_ip = ""
update_frequency = 60 #check and update frequency in Seconds. By Default every 60 seconds
#No-IP credentials and Hostname associated with the No-IP account
username = ""
password = ""
hostname = ""
while (1):
ip = get('https://api.ipify.org').text
print(f'My public IP address is: {ip}')
if last_ip != ip:
resp = get(f'http://{username}:{password}@dynupdate.no-ip.com/nic/update?hostname={hostname}&myip={ip}').text
last_ip = ip
if "nochg" not in resp or "good" not in resp:
fh = logging.FileHandler('noIP_errors.log')
logger.warning(resp)
fh.setLevel(logging.WARN)
logger.addHandler(fh)
time.sleep(update_frequency)