Send commands to DD-WRT router

Requests, suggestions, support, and everything else python / plugin related.
Post Reply
User avatar
GoTeamScotch
Posts: 268
Joined: Sat Apr 06, 2013 2:17 am
Has thanked: 97 times
Been thanked: 75 times

Send commands to DD-WRT router

Post by GoTeamScotch »

I'm currently in the process of taking up Python and getting familiar with it. I've been sifting through documentation and online references to make a script that can send commands to a DD-WRT based router via telnet commands. At this stage the script loads, goes to a black screen and displays the output from the telnet session. It's very rough and ugly but so far so good :) . At this stage I'm just having troubles with how to get the output to display correctly. I'm using ControlLabel (xbmcgui.ControlLabel) to display output but I'm starting to get the feeling that it's only meant for titles because there appears to be a width limit.

Background: I'm building a custom Xbox with a stripped down Belkin wireless router with DD-WRT installed inside of it, and I need to set it up as a Repeater Bridge (already done, works fine). But the thing is, there will be times where I'll need to connect it to other wifi networks or change the way the router behaves through a set of predefined commands. Later on it will eventually scan for nearby access points, return a list of SSID's (and ask for a passkey if required), but baby steps first, right?

Anyways, so main question: What's the best way to display (and later update) text on screen?

Current code (works)

Code: Select all

import xbmc, xbmcgui
import sys
import telnetlib

host = "192.168.1.2"
user = "root"
password = "admin"

tn = telnetlib.Telnet(host)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
   tn.read_until("Password: ")
   tn.write(password + "\n")

tn.write("nvram show\n")
tn.write("exit\n")
nvram_result = tn.read_all()

ACTION_PREVIOUS_MENU = 10
 
class toolsmain(xbmcgui.Window):
  def __init__(self):
    self.strActionInfo = xbmcgui.ControlLabel(20, 20, 200, 600, '', 'font13', '0xFF00FF00')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('DD-WRT Tools')
 
  def onAction(self, action):
    if action == ACTION_PREVIOUS_MENU:
      self.confirmexit()
 
  def confirmexit(self):
    dialog = xbmcgui.Dialog()
    if dialog.yesno("Confirm Exit", "Are you sure you want to exit?"):
      self.close()
 
mydisplay = toolsmain()
mydisplay.strActionInfo.setLabel(nvram_result)
mydisplay .doModal()

del mydisplay
Which shows up as:
Image

Edit: fixed the above code to display in full width thanks to a member's recommendation at the Xbmc.org forums. If anyone's interested in this idea to use, feel free to contact me via this thread or through PM.
Image
Remember kids, always zero-ize your HDD key!
00diabolic
Posts: 35
Joined: Sun Jun 09, 2013 8:33 pm
Has thanked: 5 times
Been thanked: 3 times

Re: Send commands to DD-WRT router

Post by 00diabolic »

I have no idea how to help but what a cool idea.. I use a DD-Wrt router in client bridge mode to wirelessly connect my xbox to my main router for internet. Have you looked into client bridge as opposed to repeater bridge the hit to bandwidth is nill in client mode.
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Send commands to DD-WRT router

Post by Dan Dar3 »

I'd say you're better off using a TextBox instead of a Label, see here (I'm posting a link to mainline docs cause I can't seem to find the XBMC4Xbox specific ones sorry)
http://mirrors.xbmc.org/docs/python-doc ... rolTextBox

Actually, the ones in our wiki point to the mainline too, ah well...
http://www.xbmc4xbox.org.uk/wiki/Python_Development

PS: If you intend to create a more complex UI, you will probably want to look into skinning and Window XML - they would allow a better design per resolution (PAL, NTSC, wide etc) and different resources (bitmaps) per skin (or a single one as a default) and more importantly the separation between presentation and behaviour. It gets somewhat easier in the code too, as you won't be creating controls and defining sizes and positions and whatnot, that'll be done in the UI XML, in the code you can just have:

Code: Select all

  TEXT_CONTROL_ID           = 30010
  ...
  getControl( TEXT_CONTROL_ID ).setText( ... ) 
You can see what I've done a while ago with XBMC4Xbox Installer, look at default.py and this one which shows a build info in a dialog with two buttons at the bottom, as a startup example if you want.
https://code.google.com/p/xbmc4xbox-add ... ld_info.py

This is a few screenshots to see how it looks like to get an idea if you never ran it before:
https://code.google.com/p/xbmc4xbox-add ... _Installer

BTW, when I developed this it was a pain in the arse to upload every little change and test it on Xbox - I believe I developed this on Windows on an XBMC 8.x or 9.x version (old, around the time the project was split). This way I could use Eclipse with PyDev (or if you prefer a light text editor, Notepad++), make changes and test them quickly right there on your PC.

If you want me to show you how I used to do things, maybe it'll help to get you started I could maybe show it to you in a TeamViewer session sometime.
User avatar
GoTeamScotch
Posts: 268
Joined: Sat Apr 06, 2013 2:17 am
Has thanked: 97 times
Been thanked: 75 times

Re: Send commands to DD-WRT router

Post by GoTeamScotch »

Thanks a lot for the tips dan dar3. You seem to know what works best. Yeah I can see that script uses things that may come in handy. It would a great place to start for someone like me, just diving into python. I have experience in web code and design, so it's been fun trying something new. I've been studying how other scripts work, specifically the Pandora radio script for xbox and a script that sends shutdown commands to windows computers via telnet, which is a little too convenient in terms of my goal with this script.

That would be great! I'd love getting insider info on setting up a dev environment for python. I have installed pydev already and have just yet to crack it open. Do you live in the uk or the states? I work ~50 hrs/wk, hopefully we both find free time someday soon.

I would like to get into gui for this script too. I tweaked the Pandora script mentioned above, so I have a base idea of how the xml works. We'll see what becomes of this simple script. DD-Wrt has quite an expansive list of commands and configurations you could set via telnet. So far I have plans of making it able to scan nearby AP's and accept username/pw to login. After that I'll add backup/restore (stored on the xbox?), changing the router mode (gateway, switch, bridge, repeater, etc) and back, and just see what else might be useful while implementing those.

00diabolic wrote:I have no idea how to help but what a cool idea.. I use a DD-Wrt router in client bridge mode to wirelessly connect my xbox to my main router for internet. Have you looked into client bridge as opposed to repeater bridge the hit to bandwidth is nill in client mode.
I didn't consider the speed factor when doing it. I figured it would be cool to have it extend my current wireless network while simultaneously providing Ethernet ports, but I have noticed slower ftp transfers over wireless. Changing between modes like repeater bridge and client bridge is something I will have the script do as well. Would you be willing to test when I have more complete versions made?

Got the script working in full screen. Just had to add one line defining the full width of the screen and presto! A helpful guy at Xbmc forums suggested
Image
Remember kids, always zero-ize your HDD key!
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Send commands to DD-WRT router

Post by Dan Dar3 »

I live in Ireland so I'm GMT - you can send me an email at dan.dar33 at gmail.com if you want to get together for an hour or so one evening or weekend. You seem to know some stuff already, so it will probably be very easy for you to pick new things - and it's a hell of a lot easier through talk and show than in writing.
fxmech
Posts: 673
Joined: Wed Aug 01, 2012 9:15 am
Has thanked: 37 times
Been thanked: 46 times

Re: Send commands to DD-WRT router

Post by fxmech »

GoTeamScotch - I will be happy to test it for you.

I run tomato usb firmware lately. I find it is mostly interoperable among the devices that can use dd-wrt. I highly recommend it. It supports many of the same features (like optware); and is much less buggy and unpredictable in the web ui. It's a ton nicer for tweaking settings and monitoring (live graphing).

That all being said, I will happily flash something back to dd-wrt for this project. I have 3 Belkin ShareMax N300's for experimenting on. Oh, and lookie here! 3 Xbox waiting to be messed with! I'll definitely add this to my list of things to try myself. Good idea!

As far as with speed is concerned; 00diabolic is correct. Client bridged will provide much more reliable results. If your Xbox boasts 4 extra ports, who would want the extended wifi anyhow? I've done it and it works great.

Dan - I appreciate your helpful posts here. You have saved me the mental fortitude of organizing the dev environment. At least a little. Plan to be writing many a script myself.
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Send commands to DD-WRT router

Post by Dan Dar3 »

The offer to show you how I do (or used to do) things / pass the knowledge is open to anyone (not saying is the best or anything, but who knows in some case might be better and easier than the way you were doing it :-) I know I took most of it from others and polished it, I hate wasting time when you could so something else with it). Anyone can just let me know and I can show you my way.

There's even ways for easy collaboration, like using Eclipse / PyDev and Google Code (SVN) say for sharing code and working and making changes together, deploy them locally then and test. It can be quite a satisfying process collaborating with other people and building something new and useful.
User avatar
2 Bunny
Posts: 99
Joined: Mon Dec 31, 2012 4:55 pm
Location: United States
Has thanked: 13 times
Been thanked: 3 times
Contact:

dd wrt reply

Post by 2 Bunny »

00diabolic wrote:I have no idea how to help but what a cool idea.. I use a DD-Wrt router in client bridge mode to wirelessly connect my xbox to my main router for internet. Have you looked into client bridge as opposed to repeater bridge the hit to bandwidth is nill in client mode.
Me too! DD WRT is the way to go. I actually have it configured as a repeater bridge with a different wireless SSID and speeds are just fine. Very handy.
User avatar
GoTeamScotch
Posts: 268
Joined: Sat Apr 06, 2013 2:17 am
Has thanked: 97 times
Been thanked: 75 times

Re: Send commands to DD-WRT router

Post by GoTeamScotch »

Hey guys, just wanted to let you all know I had to back-burner this project for a little bit but will pick it back up as time permits. There's been a ton of work for me to do at my job what with writing a WordPress-based statistics plugin while making a new site theme AND migrating it all to a dedicated server so free time has been sparse lately. I'll be tinkering here and there on the weekends though and post updates as they're available.
Image
Remember kids, always zero-ize your HDD key!
Post Reply