-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateIP.py
34 lines (26 loc) · 1.12 KB
/
updateIP.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
31
32
33
34
#!/usr/bin/python3.4
import urllib.request
class Domain:
name = ""
updateUrl = ""
currentIP = ""
registeredIP = ""
def __init__(self, name, updateUrl):
self.name = name
self.updateUrl = updateUrl
self._setCurrentIP()
self._setRegisteredIP()
def _setCurrentIP(self):
data = urllib.request.urlopen("http://ip-api.com/line/?fields=query").read()
self.currentIP = data.decode("utf-8").strip()
def _setRegisteredIP(self):
data = urllib.request.urlopen("http://ip-api.com/line/" + self.name + "?fields=query").read()
self.registeredIP = data.decode("utf-8").strip()
domains = []
domains.append(Domain("example.com", "https://freedns.afraid.org/dynamic/update.php?SoMeWeIrDHex"))
domains.append(Domain("example2.com", "https://freedns.afraid.org/dynamic/update.php?SoMeWeIrDHex"))
for domain in domains:
if domain.currentIP != domain.registeredIP:
urllib.request.urlopen(domain.updateUrl)
print("Updated IP for " + domain.name + " to " + domain.currentIP)
print("===========================================\n")