t1100mfp
New Around Here
Hi,
I would like to share the script I created to automatically reboot daily my Xfinity Gateway.
I came up with it because the router started gave ridiculously low download speeds (~20Mbps) and doing a reboot solved the issue.
I used my Raspberry Pi 4 to do the job, but any computer running Linux can be used.
Xfinity Gateway (xFi) hardware information:
- Model:CGM4981COM
- Vendor:Technicolor
- Hardware Revision:2.0
Computer prerequisites:
- Python 3 available, with Selenium installed
- Firefox installed
- Download the Selenium geckodriver (if possible copy it to /usr/local/bin)
- Install the python script using crontab -e, and remember to define the PATH var to include the path where the geckodriver was placed, e.g.
You can use https://crontab.guru/ to see more options.
Here's the script:
The output will be something like this:
I hope this can be helpful to someone else.
Thanks.
I would like to share the script I created to automatically reboot daily my Xfinity Gateway.
I came up with it because the router started gave ridiculously low download speeds (~20Mbps) and doing a reboot solved the issue.
I used my Raspberry Pi 4 to do the job, but any computer running Linux can be used.
Xfinity Gateway (xFi) hardware information:
- Model:CGM4981COM
- Vendor:Technicolor
- Hardware Revision:2.0
Computer prerequisites:
- Python 3 available, with Selenium installed
- Firefox installed
- Download the Selenium geckodriver (if possible copy it to /usr/local/bin)
- Install the python script using crontab -e, and remember to define the PATH var to include the path where the geckodriver was placed, e.g.
Code:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
0 5 * * * /home/hugo/scripts/reboot-xfi.py 2>&1 >> /home/hugo/scripts/output.log
You can use https://crontab.guru/ to see more options.
Here's the script:
Python:
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver import FirefoxOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import logging
import sys
import time
DEBUG=False
logging.basicConfig(
# filename="selenium-test.log",
format="%(asctime)s %(levelname)s %(message)s",
stream=sys.stdout,
level=logging.INFO
)
# credentials
username = "admin"
password = "xxx" # put your own password
if __name__ == "__main__":
logging.info("STARTING application")
opts = FirefoxOptions()
opts.add_argument("--headless")
logging.info("Creating driver (opening browser window)")
driver = webdriver.Firefox(options=opts)
logging.info("Loading login page")
driver.get("http://10.0.0.1")
logging.info("Entering login information")
driver.find_element(By.ID, "username").send_keys(username)
driver.find_element(By.ID, "password").send_keys(password)
logging.info("Submitting login form")
driver.find_element(By.CLASS_NAME, "btn").click()
WebDriverWait(driver=driver, timeout=10).until(
lambda x: x.execute_script("return document.readyState == 'complete'")
)
logging.info("Loading reset webpage")
driver.get("http://10.0.0.1/restore_reboot.jst")
WebDriverWait(driver=driver, timeout=10).until(
lambda x: x.execute_script("return document.readyState == 'complete'")
)
logging.info("Clicking reset button")
driver.find_element(By.ID, "btn1").click()
if not DEBUG:
logging.info("Confirming dialog box")
driver.find_element(By.ID, "popup_ok").click() # the gateway modem takes aprox. 2 minutes to be online again
logging.info("Waiting for the reset action to be processed")
time.sleep(30) # sleep for 30 seconds, this will give time for the request to be processed and to be logged out
logging.info("Quitting driver (closing browser)")
driver.quit()
The output will be something like this:
Code:
2022-11-11 05:00:01,584 INFO STARTING application
2022-11-11 05:00:01,584 INFO Creating driver (opening browser window)
2022-11-11 05:00:08,255 INFO Loading login page
2022-11-11 05:00:10,264 INFO Entering login information
2022-11-11 05:00:10,986 INFO Submitting login form
2022-11-11 05:00:15,386 INFO Loading reset webpage
2022-11-11 05:00:17,242 INFO Clicking reset button
2022-11-11 05:00:17,777 INFO Confirming dialog box
2022-11-11 05:00:18,117 INFO Waiting for the reset action to be processed
2022-11-11 05:00:48,148 INFO Quitting driver (closing browser)
I hope this can be helpful to someone else.
Thanks.