-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip-touch.py
executable file
·53 lines (43 loc) · 1.47 KB
/
ip-touch.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from classes import YandexPdd
from ipaddress import ip_address
import configparser
import socket
def main():
config = configparser.RawConfigParser()
config.read('config')
try:
targetDomain = config.get('General', 'targetDomain')
targetSubdomain = config.get('General', 'targetSubdomain')
targetIP = config.get('General', 'targetIP')
except configparser.Error as e:
print(e)
return False
app = YandexPdd()
if len(app.errors) > 0:
print(app.errors)
return False
# Ищем локальный IP
if targetIP == 'local':
newIP = socket.gethostbyname(socket.gethostname())
elif targetIP == 'external':
newIP = app.getExternalIP()
else:
newIP = targetIP
try:
newIP = ip_address(newIP)
except ValueError as e:
print("Неверно указан IP адрес: ", e)
return False
app.getDomains()
dnsRecord = app.searchDnsRecord(targetDomain, targetSubdomain)
if not dnsRecord:
print( "Искомый поддомен не найден.")
return False
# Если все ок, меняем IP адрес и сохраняем
dnsRecord.content = newIP
if dnsRecord.save():
print( "IP адрес успешно обновлен." )
if len(app.errors) > 0:
print("При выполнении приложения возникли ошибки: ", app.errors)
if __name__ == '__main__':
main()