Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically changing wireless router settings - Netgear ideally

Tags:

Is it possible to programmatically change settings on a Netgear wireless router using C#? I have settings that I change often and I would like to create my own interface for making those changes. Currently I navigate to the admin web page (10.0.0.1) and it prompts me for a username and password. After I authenticate I can use the web interface to change the router's configuration.

If this isn't possible with Netgear, do any outher wireless routers have an API for developers?

like image 838
DarLom Avatar asked Jun 10 '10 19:06

DarLom


People also ask

What are the best settings for a Netgear wireless router?

The Maximum Transmission Unit is the largest single packet of data your Netgear router transmits. Netgear states that although "adjust the MTU setting" is a common recommendation for improving performance and speed, leaving it at the factory default is usually the best choice.


2 Answers

There aren't any APIs out there to do this, but you can write something to make HTTP requests to the router to simulate the webUI being used.

I'm guessing most consumer routers are probably pretty simple to talk to. Authentication is probably nothing more than basic realm.

like image 69
chris12892 Avatar answered Sep 27 '22 02:09

chris12892


Selenium offers a firefox plugin that lets you record manual interactions with your browser. And then you can export the steps to python, ruby, java or c#. It worked for me to programmatically adjust my router settings to turn off wifi. Clicking on the elements while recording identifies everything you need.

This code works on an Actiontec MI424WR (FIOS)
Edit the code to add your username, password, and router address.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class Routr(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://routerip_or_address"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_routr(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_name("user_name").clear()
        driver.find_element_by_name("user_name").send_keys("your_username")
        driver.find_element_by_id("pass2").clear()
        driver.find_element_by_id("pass2").send_keys("enter_your_password_here")
        driver.find_element_by_link_text("OK").click()
        driver.find_element_by_link_text("Change Wireless Settings").click()
        driver.find_element_by_id("ws_off").click()
        driver.find_element_by_link_text("Apply").click()

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException, e: return False
        return True

    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
like image 38
Antonios Hadjigeorgalis Avatar answered Sep 23 '22 02:09

Antonios Hadjigeorgalis