Last active
December 29, 2018 22:59
-
-
Save SavinaRoja/fe1e9cc97ef081b8b16648c71fa23fe9 to your computer and use it in GitHub Desktop.
A Selenium based script to automate dynamic dns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
A little script to automatically update my 'home' subdomain on A2 Hosting. No API | |
access so I implemented it with Selenium. Very simple now, might become more elaborate | |
later is needed. | |
""" | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from requests import get | |
import time | |
USERNAME = '' | |
PASSWORD = '' | |
if __name__ == '__main__': | |
ip = None | |
while True: | |
time.sleep(600) | |
new_ip = get('https://api.ipify.org').text | |
if new_ip == ip: | |
continue | |
ip = new_ip | |
driver = webdriver.Chrome() | |
driver.get('https://my.a2hosting.com/clientarea.php') | |
username_input = driver.find_element_by_name('username') | |
username_input.send_keys(USERNAME) | |
password_input = driver.find_element_by_name('password') | |
password_input.send_keys(PASSWORD) | |
password_input.send_keys(Keys.RETURN) | |
driver.get('https://my.a2hosting.com/clientarea.php?action=domaindns&domainid=92963') | |
dns_records = driver.find_elements_by_xpath("//form[@class='form-horizontal']/table/tbody/tr") | |
for record in dns_records: | |
hostname_el, record_el, address_el, priority_el = record.find_elements_by_tag_name('td') | |
hostname = hostname_el.find_element_by_xpath("input[@type='text']").get_attribute('value') | |
if hostname == 'home': | |
address_input = address_el.find_element_by_tag_name('input') | |
address_input.clear() | |
address_input.send_keys(ip) | |
save_element = driver.find_element_by_xpath("//form[@class='form-horizontal']/p/input[@value='Save Changes']") | |
driver.execute_script("arguments[0].click();", save_element) | |
driver.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=My Dynamic DNS script for A2 Hosting | |
Requires=network.target | |
After=network.target | |
[Service] | |
ExecStart= /home/pi/mydyndns/bin/python /home/pi/mydyndns/mydyndns.py | |
Type=simple | |
User=pi | |
Group=pi | |
StandardOutput=null | |
PrivateTmp=true | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment