Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1] 2

Author Topic: Controlling modems remotely  (Read 7896 times)

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Controlling modems remotely
« on: May 03, 2018, 03:02:47 AM »

I suspect that if I can find the energy then I can now remotely monitor and remote control my three DLink modems using my ipad or some other machine using http.

I have managed to write a heap of tools for the ipad that can monitor the state of the lines by talking to my router (a Firebrick) over http. It has been very fiddly because I have had problems because the data returned has a variable or at least hard-to-parse format after it is output by the library routines I am stuck using - it changes format (in a sense) according various line or modem related error conditions. And basically screen-scraping the web ui has not been that easy partly because of the limitations of the tools I have used and partly because of the general fact that the web tends to be only fit for human consumption and is not usually designed for maximum machine-readable friendliness. Using the WorkFlow programming language engine for the iPad I can check the status of modems and dsl lines, find modem vs port vs line interconnection mistakes, send new config xml to the router, and remote reboot it.

I suppose I could do something similar by talking to the modems’ http admin interfaces, check error rates and force them to sync now if there are problems. G.DMT has done a lot of excellent work in talking to this model of modem, much of it using telnet, some of it using http, I forget.

If my raspberry pi were working then I could run it on that. But I would have a lot of choices to make about tools and libraries. One good thing then would be that a monitoring server process could more easily run continuously. Mind you, I could have something running continuously on my older, spare iPad, provided that it does not decide to go to sleep for some reason.

One problem would be that of gathering stats and spotting resynch events. Perhaps I just say that if an error count goes down, then there has just been a resync and I have lost some data in the interval between polls when I query a modem for stats, so I just difference values and ignore differences that are negative.

If I send the modem an http request, it just immediately generates a page prompting me to login with username and password. I tried sending http ‘basic authentication’ with the original request to see if I could sweet talk it that way, but no luck, assuming I got the format right (used the example of code that I have used successfully for this before in talking to a Firebrick by http) then perhaps it just doesn't support this.

What kind of stuff should I send it to login ? I've never done exactly this before.

[Moderator edited to merge two successive posts.]
« Last Edit: May 13, 2018, 06:57:06 AM by Weaver »
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #1 on: May 03, 2018, 08:30:10 PM »

Actually, a thought, our hero who wrote MDWS might know how to http log in to a router’s web admin interface? Unless that is entirely telnet-based alone though.
Logged

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43568
  • Penguins CAN fly
    • DSLstats
Re: Controlling modems remotely
« Reply #2 on: May 03, 2018, 10:41:24 PM »

MDWS  depended on uploads from monitoring programs using telnet to access the stats.
Logged
  Eric

displaced

  • Reg Member
  • ***
  • Posts: 270
Re: Controlling modems remotely
« Reply #3 on: May 03, 2018, 10:43:23 PM »

In a previous job I wrote some software to configure some old D-Link DWP access points by faking http web page requests.  The devices didn't support telnet config, so I had to script all the form content and auth stuff for each request.

Your best friend is Wireshark, and the Chrome or Safari Web Inspector.  Just as a general tip, keep an eye out for cookies and hidden form values.  Often, visiting the login page will issue a session cookie, which you'll need to store and include with future calls. 

Use Web Inspector to see what's going back and forth during a 'real' login, and use Wireshark to cross-reference.

Good luck -- I'm sure it's do-able!
Logged
YouFibre 1Gbit, OPNsense on Intel N100.  Ubiquiti UAPs.

andyfitter

  • Reg Member
  • ***
  • Posts: 172
Re: Controlling modems remotely
« Reply #4 on: May 04, 2018, 02:42:47 AM »

The web proxy ’Charles’ running on a Mac is very useful too. Slightly easier interface than wireshark which can be a bit intimidating.
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #5 on: May 04, 2018, 02:21:13 PM »

I used a tool to look at the html source - results are very weird with lots and lots of javascript crap involved in calculating hashes. I don't seem to have got things right, although I don't see any error message, which is just the way it chooses to behave if you have got the password wrong I suspect.

The html shows user name and password entry fields as you would expect, but then there are also two other fields with strange long names, of type hidden, and it looks as if there is javascript code that is supplying md5 hashes of the username and password values as well, which I just don't understand at all. I could certainly understand ‘instead’. It seems I have failed to replicate this setup in my own code.
« Last Edit: May 04, 2018, 03:24:14 PM by Weaver »
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #6 on: May 04, 2018, 10:16:35 PM »

I have attached the modem html to this post - perhaps someone will tell me where I am being so stupid, it's just confusing me.
Logged

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Controlling modems remotely
« Reply #7 on: May 04, 2018, 11:19:53 PM »

I don't know if it is significant but shouldn't lines 3 & 4 just be one contiguous line? (I.e. no new line character between the pair of them?)
Logged
:cat:  100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

Please consider making a donation to support the running of this site.

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #8 on: May 04, 2018, 11:36:46 PM »

I did a copy-paste from the view-source tool that I used on my iPad, I didn't download the html properly, so perhaps that is just a mistake due to the formatting introduced by the tool.
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #9 on: May 05, 2018, 08:48:13 AM »

Sanity check: I send back the long-ish textual secret as the value of the Login_Pwd field and the md5 hash of the actual password as the value of the hidden password field whatever that is called. The username just goes back straight. Anything else I need to be doing?

I am going mad.

I am not sure what the Workflow programming language for iOS is doing with all of this. I have told it to do a http post and that the data is a form, so I am hoping that it will url-encode the field values and concatenate them sticking ”&” characters between each field, is that right? But I can't see what's going on underneath and if the modem is unhappy I can't see what I got wrong.
Logged

andyfitter

  • Reg Member
  • ***
  • Posts: 172
Re: Controlling modems remotely
« Reply #10 on: May 05, 2018, 11:41:33 AM »

Looks like the Charles proxy is available for iOS now too. You could install this on your iPad and see exactly what it is sending over WiFi

https://itunes.apple.com/gb/app/charles-proxy/id1134218562?mt=8
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #11 on: May 05, 2018, 01:41:55 PM »

Andy you're a star. That tool is incredibly useful. Thank you so very much.

I spotted the mistake, I had got the url wrong, everything else I had guessed correctly.

I am now in.
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #12 on: May 05, 2018, 03:48:40 PM »

I can now poll all known modems for stats, have an automated monitoring server watch them like a hawk continuously for evil. I could say watch out for too many errors or snrm going bad or who knows what. I should then also be able to remotely force a resynch with a little more digging around.

I would need to get telnet going perhaps to get more detail. Kitizen hero G.DMT has already written a ton of code to talk to these modems, some of it using telnet.
Logged

andyfitter

  • Reg Member
  • ***
  • Posts: 172
Re: Controlling modems remotely
« Reply #13 on: May 05, 2018, 04:38:14 PM »

Andy you're a star. That tool is incredibly useful. Thank you so very much.

No problem, glad to help. Been an iOS developer for 9 years and it’s been a lifesaver for me many times both for reverse engineering and checking implementation.
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Controlling modems remotely
« Reply #14 on: May 07, 2018, 03:28:17 PM »

Duh. I have now noticed that kitizen G.Dmt wrote all the code to do exactly this and posted it up two years ago in an earlier thread, and I never noticed, anyway completely forgot. God what a fool I am. :-[
Logged
Pages: [1] 2