Script to disconnect Linksys WRT54G wireless router on Windows

I do not know if this helps but this is the web page at the Linksys WRT54G router page "Status -> Router" https://192.168.0.1/StaRouter.htm

A:hover { COLOR: #00ffff } .small A:hover { COLOR: #00ffff }

var refresh_time = ""; var flag=0; function DHCPAction(F,I) { F.action.value=I; F.submit(); }

function ConnStats(obj) { var F=document.status; if(flag == 1){ F.action.value="Connect"; } else{ F.action.value="Disconnect"; } F.submit(); }

function GetWAN() { var F=document.status; var wan_num=F.wan_pro.value; if(wan_num==2){ if (((F.conn_stats.value=="-1")&&(status2!="Connecting"))||((F.conn_stats.value=="201")&&(status2!="Connecting"))||((F.conn_stats.value=="202")&&(status2!="Connecting"))||((F.conn_stats.value=="203")&&(status2!="Connecting"))||((F.conn_stats.value=="200")&&(status2!="Connecting"))){ flag = 1; F.butConn.value=stacontent.connect; } else{ F.butConn.value=stacontent.disconnect; flag = 0; } } else if((wan_num==3) || (wan_num==4) || (wan_num==5)){ if((F.conn_stats.value=="-1")&&(status2!="Connecting")){ flag = 1; F.butConn.value=stacontent.connect; } else{ flag = 0; F.butConn.value=stacontent.disconnect; } } } function ShowAlert(M) { var str = ""; var mode = ""; /* */ var wan_ip = "69.110.22.230";

if(document.status.wan_pro.value == 2) mode = "PPPoE"; else if(document.status.wan_pro.value == 3) mode = "PPTP"; else if(document.status.wan_pro.value == 4) mode = "L2TP"; else if(document.status.wan_pro.value == 5) mode = "HBS"; else mode = "PPPoE";

if(M == "AUTH_FAIL" || M == "PAP_AUTH_FAIL" || M == "CHAP_AUTH_FAIL") str = mode + stacontent.authfail; else if(M == "IP_FAIL" || (M == "TIMEOUT" && wan_ip == "0.0.0.0")) str = stacontent.notgetip + mode + stacontent.wansrv + stacontent.wansrvlastwords; else if(M == "LCP_FAIL") str = mode + stacontent.lcpfail; else if(M == "TCP_FAIL" || (M == "TIMEOUT" && wan_ip != "0.0.0.0" && (document.status.wan_pro.value == 5))) str = stacontent.notcpconn + mode + stacontent.wansrv; else str = stacontent.notconn + mode + stacontent.wansrv;

alert(str);

Refresh(); } var value=0; function Refresh() { if(refresh_time == "") refresh_time = 60000; if (value>=1) { window.location.replace("StaRouter.htm"); } value++; timerID=setTimeout("Refresh()",refresh_time); } function ViewDHCP() { dhcp_win = self.open('DHCPTable.htm','inLogTable','alwaysRaised,resizable,scrollbars,width=720,height=600'); dhcp_win.focus(); } function init() { var F=document.status; var wan_num=F.wan_pro.value; if((wan_num>=2) && (wan_num =2) && (document.status.wan_pro.value document.write("

Reply to
Wilson
Loading thread data ...

Most WAN-routers also have a textual interface (like telnet) that is much easier to handle programmatically, so why go the non-easy way?

Reply to
Dr.Ruud

I'll see if we have it saved somewhere. We haven't worked with Linksys units for some time.

Reply to
DTC

Thanks.

Reply to
Wilson

I am almost to the point of giving up on Perl so I think I'll follow Ben's prior suggestions which seem to be more powerful than Perl.

I think, based on my experience only, that for Perl to interpret Javascript is something nobody has ever posted, so, who am I, an avowed beginner and non programmer, to get it working first.

I have just one or two more experiments to try. I don't have a programmers' mind, but I do see a few more things I can tweak and try as every time I try something, I see something else that "might" be the culprit or the solution.

I find that part fun even though I don't know how to program. I sure hope to post a solution for the world to benefit - but first I have to get it working.

Thanks for the advice.

Reply to
Wilson

Hi Ben, You have always been the one useful voice of reason. The rest were voices of reason, but not useful (like the ones who lambasted my lack of programming experience or those who claimed it could be done w/o any evidence). They were right, of course, but they weren't helpful to getting the task accomplished.

For your insight, I appreciate. I will try just a couple more experiments with the Perl approach as I hate to lose. I'm not a programmer, nor do I have a programmer's mentality, but, I just hate it when something should work but it doesn't for some unknown reason. That irks me and irked me in my dreams all night, sadly to say.

Anyway, I'll be re-reading your posts and attempting the closest thing to what looks like it will work to perform the following:

a) Open an https web page on the Linksys WRT54G router b) Log in with a username of null and a password of "letmein" c) Press a javascripted button on that web page called "Disconnect"

Thanks!

Reply to
Wilson

Hi Sherman, After calming down, I must apologize for saying "Perl can't do it", as, as you noted, I am not a programmer, nor do I have a programmer's mentality ... so who am I to say whether it can be done or not. In my frustration, I guess I was "blaming" perl but I did not mean to malign that language.

It's just that I really hate it when I have to do anything manual and, despite the fact I'm not a programmer-type person, I always try to cut down on the number of button clicks I do, even if it's only three or five clicks when I do it a lot. I find that makes me much more efficient even if there is a lot of up-front work to get the job done.

So, I _will_ automate the task of disconnecting and reconnecting from the ISP - I just don't know how yet. I have just a few more things to try (although I said that days ago) and I'll get the damn thing working.

Thanks and sorry for not being of the mind and body like you guys are! I admire you and what you can do with code! Wilson

Reply to
Wilson

No, WWW::Mechanize doesn't run the JavaScript. But to be fair, you didn't mention the JavaScript requirement - all you said was that Perl couldn't fetch an https page and click a button. :-)

One approach you might try is viewing the source of the HTML page in your browser, figuring out what the JS does in a browser, and then writing the same behavior into your Perl script.

JS is annoying enough. Makes me happy I haven't upgraded my ancient BEFSR41. :-)

sherm--

Reply to
Sherman Pendley

Hey, you can learn to work the computer, or let the computer work you.

Yep, computer is nice for automation and repetitive tasks.

I do not do windows, I run Mandriva Linux. I plugged Mechanize into my Software Management application search box, and 7t'h selection click gave me

perl-WWW-Mechanize-Shell - WWW::Mechanize::Shell - An interactive shell for WWW::Mechanize

This module implements a www-like shell above WWW::Mechanize and also has the capability to output crude Perl code that recreates the recorded session. Its main use is as an interactive starting point for automating a session through WWW::Mechanize.

Reply to
Bit Twister

Wilson

As I stated, my WRT54G is configured differently than yours -- no "disconnect" or "connect" button under "Status -> Router".

While c.l.p.m is not the proper newsgroup for this, I see from your HTML posting, that you have your WRT54G set to use PPPoE. Mine is not.

Let me guess at your problem. Your DSL modem changes public IP address on occasion. When it does you need to re-connect your WRT54G to get the new pubic IP address as well. Am I correct?

I set my WRT54G to use a Static IP (Setup -> Basic Setup). My DSL modem's IP address is 192.168.1.1

I use the following settings for the WRT54G: Internet IP Address: . . . 192.168.1.10 Subnet Mask: . . . 255.255.255.0 Gateway: . . . Static DNS 1: . . . my ISPs 1st DNS server Static DNS 2: . . . my ISPs 2nd DNS server Static DNS 3: . . . 0.0.0.0

Local IP Address: . . . 192.168.2.1 Subnet Mask: . . . 255.255.255.0

I then have no need to disconnect and re-connect the WRT54G when my DSL's pubic ip address changes.

Reply to
l v

I port scanned my WRT54G when I first got it. Unlike my DSL modem, it does not respond to telnet nor ssh. I am guessing the OP's wireless device is the same.

Reply to
l v

Err, no; you misunderstood me. The tool I pointed you at (WSP) helps find out what's actually going on between the browser and the router, so you can then emulate that in Perl (or anything else, for that matter). If you were feeling macho you could just run tcpdump and work from there... :)

Ben

Reply to
Ben Morrow

In the general case, no: You need a JavaScript interpreter for that.

In most realistic cases, yes: The JavaScript code on the page is always the same, so you just need to find out what it does and reimplement it in Perl.

hp

Reply to
Peter J. Holzer

So Wilson does have a programmer's mind after all.

I didn't realize Wilson is using Windows. If he does he should be able to use WWW::Mechanize::IE, which lets him use IE's JavaScript interpreter.

hp

Reply to
Peter J. Holzer

The proof is rather simple.

1) Perl is a turing-complete programming language which provides the means to communicate over TCP. Therefore any task which can be described by an algorithm and which only requires communication over TCP can be implemented in Perl. 2) The task at hand can be done by a human using a standard web browser. 3) The part done by the browser can of course be implemented by a program since a browser is a program. 4) So the part done by the human remains: Can this be described by an algorithm? Yes: It requires only a series of simple, precicely defined steps.

Therefore the whole task can be implemented in Perl.

Of course that proof is not very useful. Writing a whole web-browser in Perl just to automate such a simple task would be a bit over the top. But it shows that it can be done in principle, and once you know one way to do it you can search for simpler ways.

hp

Reply to
Peter J. Holzer

I think I've narrowed down the problem to the acceptance of the Linksys security certificate when the Linksys WRT54G router is first contacted.

The way I tested that was to set it to http instead of https in the router configuration. Just a few more tries before I give up totally on Perl and go with something else.

Reply to
Wilson
500 read timeout
Reply to
Wilson
[f'ups set to clpm. Please stop cross-posting everything.]

Quoth Wils> > The way I tested that was to set it to http instead of https

The Client-Warning says this response is faked by LWP, and the message says that, well, a read timed out. The server isn't responding sufficiently promptly: set a longer timeout with $ua->timeout, or find out why it's failing to respond.

Ben

Reply to
Ben Morrow

You can also record and generate the script in minutes using SWExplorerAutomation (SWEA) from

formatting link

Reply to
alex

You omitted the security issue. Leaving the router wide open for a Perl script is like unprotected sex, and the security programming in Perl is non-trivial to do safely.

On Thu, 17 Jan 2008 03:05:57 -0800 (PST), snipped-for-privacy@gmail.com wrote in :

Reply to
John Navas

Cabling-Design.com Forums website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.