CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2006
    Posts
    5

    Accessing routers firmware data from My application

    Hi All!

    I am developing VB applications for sometime now but now I am working on some application that can have access over the network. My experience in network programming is not very well.

    First of all let me tell you that the router is SOHO based and has a linux kernal based firmware and can be configured through browser.

    I want to develop application that can connect to a router on LAN and then extract some information out of it and also provide some information to the firmware from application without accessing it through the web browser. Like for example the log file of the router.

    I would like to help getting started with it. I think i will be using winsock dll but am stuck at the start. If any one can give me a clue how to start then i might be doing it to the end.

    Another think i want to mention is that I can access the syslog.html file (in urs direcotory) in the firmware by telnetting and accessing the kernal by root. And they are using CGI code to generate the log, but how can i access this from my VB application

    Waiting for any help anxiously
    Regards
    Mykhan

  2. #2
    Join Date
    Jan 2006
    Location
    the second crappiest place on earth
    Posts
    88

    Re: Accessing routers firmware data from My application

    I'm getting ready to head out the door to work, so this isn't complete, but it's a start. It also uses the WinSock control, since I always use C when writing socket code the "hard way".

    General overview:

    1. Telnet to the router manually, and do what you would do to view the file. Save this information in a text file that you can refer to later.

    2. "Name" each step of the telnet session.

    3. Devise some way to keep track of where you are in the session.

    4. Send the console commands through the WinSock control, and process the responses until you're through it all.

    Here's a brief, simple sample. Pretend this represents a telnet session to view the log file on your router. It's been years since I've been on a router console, so it's obviously not very realistic, but we need this for the sake of this example:

    Lines starting with "<" are lines the router sent to you. Lines with ">" are lines you sent to the router.

    Code:
     
    < OK
    > view logfile
    < 10.1.20.1 outbound to 10.25.1.18
    < 10.1.20.19 outbound to 10.26.19.7
    < ... etc
    < OK
    Set up your WinSock control like this:

    Code:
     
    Private m_lStepCount As Long
     
    Private Sub Form_Load()
    m_lStepCount = 0
    End Sub
     
    Private Sub cmdConnect_Click()
    	With wsRouter
    	 If .State <> sckClosed Then
    		 .Close
    	 End If
     
    	 .Protocol = sckTCPProtocol
    	 .RemoteHost = strRouterIP
    	 .RemotePort = 23			' Telnet port
    	 .Connect
     
    	Wend
    End Sub
     
    Private Sub wsRouter_DataArrival(ByVal bytesTotal As Long)
    Dim strTemp As String
     
    strTemp = String$(bytesTotal, Chr$(0))
    wsRouter.GetData strTemp
     
    If Not IsError(strTemp) Then
    	Select Case m_lStepCount
    	 Case 0		' First OK was received
    		wsRouter.SendData "view logfile"
    		m_lStepCount = m_lStepCount + 1
    	 Case 1
    		If strTemp <> "OK" Then
    		 AppendLog strTemp
    		Else
    		 wsRouter.Close
    		End If
    	End Select
    End If
     
    End Sub
     
    Private Function IsError(v_strText) As Boolean
    ' Do something in here to validate what you're getting from the router
    IsError = False
    End Function
     
    Private Sub AppendLog(v_strText)
    ' Add this line of text to what you've already got...
     
    ' But *don't* do it this way...
    Static strLog As String
    strLog = strLog & v_strText
     
    End Sub
    This is very basic and oversimplified, but I think it's enough to get you headed in the right direction.

    Hope that helps...
    Joe Plocki

    Sometimes the straightest path is through the mud.
    O|||||O

  3. #3
    Join Date
    Jun 2006
    Posts
    5

    Re: Accessing routers firmware data from My application

    Thanks a lot for your help. I have tried that and had something to work with.

    But one thing, you showed the communciation on telnet but actually the communication is all done at port 80 and I want to access the log using 80 and not by telnet.

    Another problem I am facing is that I couldnt get the variables which has the log file and its path after the router's IP because the router is using CGI and I am not getting CGI at all. specially in the textarea where the log is pasted, the following CGI code is embedded.

    <textarea> <? mutliquery logger:status/log '$01 $02 /n' ?> </textarea>

    Now I am not getting that.....

    regards

  4. #4
    Join Date
    Jan 2006
    Location
    the second crappiest place on earth
    Posts
    88

    Re: Accessing routers firmware data from My application

    Got ya... the router uses a little web server for the admin stuff then. I was thinking you said it also supports telnet, and that's easier, to me, since you can send/receive exactly what you would see and do in an actual telnet session.

    Whew... to handle the port 80 stuff yourself, then, you're going to need to implement a subset of the HTML protocol in your client, and make requests as a browser would, parse the resulting page code, build the POST message... etc, etc. The CGI you won't have to worry about, as long as you make the "page" requests correctly - that'll happen in the router, and what you get back should be what you want, for free.

    Something I've done before for something like this is write a small TCP proxy, connect the proxy to the remote device, and connect the real client to the proxy. My proxy simply uses two Winsock controls, one listens and one connects, and when one receives, it just sends it out the other one. Of course, I analyze and log the data in the process. Then I just connect it all up, do it once or twice using the intended client, and start looking at my logs. From the log, I start building my connection handler, as in my earlier example. In your case, the concept could be pretty similar, just a bit more tedious because you're having to handle the HTML protocol, and possibly actually parsing the HTML page data.

    Anyway, if that sounds like a viable option to you, and if you want, I'll dig up and post the code for my little proxy here to help get you started. Heads up, though - the proxy was a tool I needed in a hurry, spent about 20 minutes on it, and never looked back. It works, but it ain't necessarily pretty on the inside.

    Let me know...
    Joe Plocki

    Sometimes the straightest path is through the mud.
    O|||||O

  5. #5
    Join Date
    Jun 2006
    Posts
    5

    Re: Accessing routers firmware data from My application

    Ok Thank you very much...at least the confusion clouds are getting over and I can see ray of hope comming out for me. The position is getting clearer so lets see what else I can do with it. Your help is really appreciated. Beside that I will be waiting for you to paste up your piece of code, in anyway it will be a lot helpful as I am a learner and would take anything for granted

    Another query: Can anyone tell me about the API controlling the IP config/all Dos command, both in windowsXP and 98.

    Regards
    Mykhan Yousafzai

  6. #6
    Join Date
    Jun 2006
    Posts
    5

    Re: Accessing routers firmware data from My application

    Quote Originally Posted by mykhan
    Another query: Can anyone tell me about the API controlling the IP config/all Dos command, both in windowsXP and 98.

    Regards
    Mykhan Yousafzai
    Done that with a shell command now

  7. #7
    Join Date
    Mar 2005
    Posts
    226

    Re: Accessing routers firmware data from My application

    If you want to access the routers data, you can use the SNMP(simple network managment protocol) and just poll the router. All routers support SNMP. Writing a VB SNMP routine is do able but it will take some work. If I had to do it over again, I would buy an SNMP active x control pre-built.

  8. #8
    Join Date
    Jan 2006
    Location
    the second crappiest place on earth
    Posts
    88

    Re: Accessing routers firmware data from My application

    Hey, mykhan...

    Sorry for the delay, here... I had to find the code, and tweak it a bit to make it flexible enough for you to use it without major modifications.

    Hope it helps... the code isn't quite as nasty as I had imagined, though it does still fall in the "I need a tool in 20 minutes" category of coding style.

    In any case, because of the way this tool works, you couldn't use it for a general purpose web proxy, but I think it'd probably be good enough to do the router stuff you were talking about. If not, my first suspicion would be the connectionless nature of HTTP, so you might have to add code to detect when the client or server disconnects, and reconnect on demand. Maybe you'll get lucky, though, and the router won't disconnect you every time you receive a "page".

    Anyway, it's pretty simple... enter the IP/host name of the device, the port you want to connect (80, most likely), and the port you want to listen to (any valid IP port number). Connect your client (web browser) to the to the proxy, specifying the connection port in whatever way the client wants. In IE, it'd be something like: http://127.0.0.1:1200, where the colon separates the host from the port, and the number following the colon is the port.

    Hope you find it useful. Heheh, and try to keep in mind that that's not my "production-quality" code in there... I never really expected anyone else to see it, and it works for my needs.

    Good luck...
    Attached Files Attached Files
    Joe Plocki

    Sometimes the straightest path is through the mud.
    O|||||O

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured