Sign in to follow this  
Followers 0
DickG

How to read router

10 posts in this topic

I looked everywhere for info on this, but haven't found it.

I would like to be able to open my router (with any browser or Inet command or whatever), then read the values that are set for it.

What I am trying to do is automate setting up my router. The reason is, in my area (Panama), the power lines are always getting glitched, which often resets the router. Then I (and the rest of us) have to reconfigure the router.

Most normal users don't have a clue on how to do this, so I am trying to automate this for them (and me, since I have to do this so often).

I tried using the AutoIt Info tool, but it doesn't give any info for the specific edit boxes where you enter IP addresses, or for dropdown lists like where you select Static or Automatic.

I would would like to find a way to read all the settings on every page of a router, then save those settings to later write them back to that page.

I know that different people use different routers, and the info on them will be different. So I am hoping to find a way to generically do this without having to know the specifics of every router.

I can find the router's IP address easy enough, so can at least open a Web page to that address. But I can't go any further until I can read those values. Using InetGet, _InetGetSource, _IEDocRead, etc. does not get the data itself, only the source code.

Any ideas?

Regards,

Dick

Share this post


Link to post
Share on other sites



I would just save the router settings to a file, then use the HTTP or IE UDF to post the file back up to the router.

Share this post


Link to post
Share on other sites

So how would you go about reading the router to get all the settings?

Pretend you are trying to read someone else's router after you send them an exe.

I would just save the router settings to a file, then use the HTTP or IE UDF to post the file back up to the router.

Share this post


Link to post
Share on other sites

I would just save the router settings to a file, then use the HTTP or IE UDF to post the file back up to the router.

I don't think he means "sho conf" in IOS. More like a home broadband/WiFi router. Some of those may have an option in the Web admin page on the LAN-side to save the config to a file, but some may not.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

So how would you go about reading the router to get all the settings?

Pretend you are trying to read someone else's router after you send them an exe.

Then you would need to know exactly what router they had, and code an IE script to configure it, since each manufacturer/model will have a different config interface.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Well I know most knew routers off an import/export settings option (My ancient Linksys BEFSR41 doesn't though). I was just saying the task of import/export could be done using the IE UDF.

Share this post


Link to post
Share on other sites

OK, I've figured it out.

Here is my code to get started. It opens your router in IE, cycles through a list of links, cycles through a list of forms for each link, then cycles through a list of elements and writes the name and value of each element to a text file.

You can change the router IP for your router, and the filename if you want.

I can "discover" the router IP, but I just hardcoded it here to save time while testing.

;Define URL to examine.
$routerIP = "192.168.1.1"

ReadRouter()

#region: Read Router
    Func ReadRouter ()
        ;Open a text file for writing (overwrite).
        $File = FileOpen(@ScriptDir & "\Linksys Router.txt", 2)

        ;Open browser (visibly for now).
        $oIE = _IECreate ("http://" & $routerIP, 0, 0)

        ;Get a list of links.
        $oLinks = _IELinkGetCollection ($oIE)
        For $oLink in $oLinks
            ;Cycle through each link to get forms.
            FileWrite($File, "Address: " & $oLink.href & @CR)
            $oForms = _IEFormGetCollection ($oIE, $oLink)
            $iNumForms = @extended
            For $i = 0 to $iNumForms - 1
                $oForm = _IEFormGetCollection ($oIE, $i)
                ;Specify form by name.
                $oForm = _IEFormGetObjByName ($oIE, $oForm.name)
                FileWrite($File, @TAB & "Form: " & $oForm.name & @CR)
                ;Get list of elements on that form.
                $oFormElements = _IEFormElementGetCollection($oForm)
                For $oFormElement in $oFormElements
                    $oText = _IEFormElementGetValue ($oFormElement)
                    FileWrite($File, @TAB & @TAB & "Element Name: " & $oFormElement.name & @CR & _
                    @TAB & @TAB & "Element Value: " & $oFormElement.value & @CR & _
                    @TAB & @TAB & "Text: " & $oText & @CR)
                Next
                FileWrite($File, @CR & @CR)
            Next
            FileWrite($File, @CR & @CR)
        Next

        ;Close things
        FileClose($File)
        _IEQuit ($oIE)

    EndFunc
#endregion

The next step will be to figure out how to read that file, find the element names and values, and write them back to the router.

Dick

I thought Netsh could modify external hardware. Correct me if im wrong.

Share this post


Link to post
Share on other sites

Whoops! The comment in my code should have been "Open router (hidden)" rather than "Open router (visibly for now)", which I did at first but changed it later to hidden. I still pops up the window to log in, though. That is all a user will see. So it can be done "behind the scene."

OK, I've figured it out.

Here is my code to get started. It opens your router in IE, cycles through a list of links, cycles through a list of forms for each link, then cycles through a list of elements and writes the name and value of each element to a text file.

You can change the router IP for your router, and the filename if you want.

I can "discover" the router IP, but I just hardcoded it here to save time while testing.

;Define URL to examine.
$routerIP = "192.168.1.1"

ReadRouter()

#region: Read Router
    Func ReadRouter ()
        ;Open a text file for writing (overwrite).
        $File = FileOpen(@ScriptDir & "\Linksys Router.txt", 2)

        ;Open browser (visibly for now).
        $oIE = _IECreate ("http://" & $routerIP, 0, 0)

        ;Get a list of links.
        $oLinks = _IELinkGetCollection ($oIE)
        For $oLink in $oLinks
            ;Cycle through each link to get forms.
            FileWrite($File, "Address: " & $oLink.href & @CR)
            $oForms = _IEFormGetCollection ($oIE, $oLink)
            $iNumForms = @extended
            For $i = 0 to $iNumForms - 1
                $oForm = _IEFormGetCollection ($oIE, $i)
                ;Specify form by name.
                $oForm = _IEFormGetObjByName ($oIE, $oForm.name)
                FileWrite($File, @TAB & "Form: " & $oForm.name & @CR)
                ;Get list of elements on that form.
                $oFormElements = _IEFormElementGetCollection($oForm)
                For $oFormElement in $oFormElements
                    $oText = _IEFormElementGetValue ($oFormElement)
                    FileWrite($File, @TAB & @TAB & "Element Name: " & $oFormElement.name & @CR & _
                    @TAB & @TAB & "Element Value: " & $oFormElement.value & @CR & _
                    @TAB & @TAB & "Text: " & $oText & @CR)
                Next
                FileWrite($File, @CR & @CR)
            Next
            FileWrite($File, @CR & @CR)
        Next

        ;Close things
        FileClose($File)
        _IEQuit ($oIE)

    EndFunc
#endregion

The next step will be to figure out how to read that file, find the element names and values, and write them back to the router.

Dick

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

If you need to make changes to posted code, just edit it and put a note at the bottom. Its also a bad idea to quote code, especially if its wrong. Then its wrong in two places.

Edited by weaponx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0