Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Launch URL via VBScript

Launch URL via VBScript

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Jeffrey F. Pia   (49 posts)  Bio
Date Fri 26 Sep 2003 12:43 AM (UTC)
Message
I have a router that crashes seemingly for no reason. It has a web-based interface through which I can reboot it remotely. I can do this just by going to a specific URL which I have bookmarked. Anyone know if it is possible to launch a URL via VBScript?

One of the plugins available detects a broken connection and attempts to reconnect. I want to modify it a tad so that it attempts to reboot the router after 5 unsuccessful reconnect attempts. Any guidance on this would be appreciated! :)
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #1 on Fri 26 Sep 2003 01:34 AM (UTC)
Message
Hmm. Depends on what you mean by launch, but I created this bit of script to check on the status of the mud I play on by reading the html page:
sub TGetStatus (Tname)
  if world.getvariable("Skip_It") = "True" then
    exit sub
  end if
  world.setvariable "Skip_It", "True"
  'world.resettimer "TGetStatus"
  dim inet
  set inet = createobject("InetCtls.Inet")
  inet.Url = "http://www.topmudsites.com/"
  inet.RequestTimeOut = 20
  dim e, f, st, en, test
  world.note "Retrieving... Standby"
  on error resume next
  e = inet.OpenUrl()
  on error goto 0
  dim RegEx, Match, Matches
  set RegEx = New RegExp
  RegEx.Pattern = "<.*agesofdespair.*>"
  set Matches = RegEx.Execute(e)
  for each Match in Matches
    test = "<tr bgcolor=#e1e1fc>"
    st = instrrev(e,test,int(Match.FirstIndex))
    test = "</tr>"
    en = instr(int(Match.FirstIndex),e,test)
    f = mid(e, st, en - st + 5)
    dim temp
    temp = split(f,chr(10))
    st = instr(temp(1),"<b>")
    en = instr(temp(1),"</b>")
    dim rank, votes
    rank = mid(temp(1),st + 3,en - (st + 3))
    st = instr(temp(6),"size=2>")
    en = instr(temp(6),"</font>")
    votes =  mid(temp(6), st + 7, en - (st + 7))
    world.send "to gossip"
    world.send "Our current ranking is " & rank & " with " & votes & " votes. Vote AoD!"
    'world.note "Our current ranking is " & rank & " with " & votes & " votes. Vote AoD!"
    world.send "www.topmudsites.com/cgi-bin/topmuds/"
    world.send "  rankem.cgi?action=in&id=aod"
    world.send "."
  next
  world.setvariable "Skip_It", "False"
end sub


The key here is these lines:

dim inet
set inet = createobject("InetCtls.Inet")
inet.Url = "http://www.topmudsites.com/"
inet.RequestTimeOut = 20
dim e
on error resume next
e = inet.OpenUrl()
on error goto 0

This will read an html page, if you need to do Post or some other thing, then this will likely not work. Though I believe that Post merely appends stuff to the line, like:

http://www.blah.com/somepage.html?Num=1&Letter=A

I don't know exactly what your URL looks like or what it actually does, but this should work in theory. A bit of a wrning though, if you use this for something 'other' than rebooting your router, since the script runs in the same thread as Mushclient, you will get some lag as it takes the time to download the page data. For me on a 56K modem, this is a delay of several seconds. :(

As an alternative you can also do:

dim ie
set ie = createobject("ie.application")
ie.browse "http://www.blah.com"

Or maybe

ie.URL = "http://www.blah.com"
ie.browse

I can't remember...
Top

Posted by Jeffrey F. Pia   (49 posts)  Bio
Date Reply #2 on Fri 26 Sep 2003 04:53 AM (UTC)
Message
I'll play around with those 2 samples. I think they should work. I don't have to post or do anything special. I simply enter a certain URL into my browser and it reboots my router. From there I am hoping the Reconnector plugin will kick in and minimize my downtime.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 26 Sep 2003 11:12 PM (UTC)
Message
If the URL doesn't actually have to send anything (or much) you might get away with having a special world that simply has that router address (port 80 unless it is a different port) and then simply make that world connect.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #4 on Sat 27 Sep 2003 04:13 AM (UTC)
Message
Probably not Nick. It may be specifically set to only accept HTTP protocal as a reset.
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #5 on Sat 27 Sep 2003 12:45 PM (UTC)

Amended on Sat 27 Sep 2003 12:46 PM (UTC) by Magnum

Message
Hmm, the oldskool way of connecting to routers used to be to telnet into them. Now, since MUSHclient is essentially just a fancy-shmancy telnet program....

I have a D-Link DI-604 firewall/router. I just tried to telnet to it, and unfortunately, can not. Seems the new trend is http only. I also pulled up the PDF manual for the device and searched for 'telnet', but the only result was not relevant.

At any rate, I would check if your model supports telnet connections, and if so, you could probably create a "world" in MUSHclient that connects to your router, and you could use MUSHclient as your interface to the device.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 30 Sep 2003 06:40 AM (UTC)

Amended on Tue 30 Sep 2003 06:42 AM (UTC) by Nick Gammon

Message
The difference between a MUSHclient connection and an HTTP one is really only what gets sent as text. See this link:


http://www.jmarshall.com/easy/http/


This is a tutorial on the HTTP protocol.

Now if you made MUSHclient connect to the router, and as part of the auto-connect string sent something like this:


GET / HTTP/1.0
(blank line here)


It would think you are requesting the root document from your web server. I did exactly that as a test on my intranet server and it worked perfectly. I got this response:


HTTP/1.1 200 OK
Date: Tue, 30 Sep 2003 06:38:34 GMT
Server: Apache/2.0.46 (Unix) PHP/4.3.2
X-Powered-By: PHP/4.3.2
Connection: close
Content-Type: text/html; charset=ISO-8859-1

<html>

------- yadda yadda here ----------

</html>
--- Disconnected on Tuesday, September 30, 2003, 4:38 PM ---
--- Connected for 4 seconds ---


So, get the address and port right, send a request for the right document, and it (the router) thinks it is talking to a web browser.




- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Tue 30 Sep 2003 07:26 AM (UTC)
Message
Can you not use the ShellExecute Windows API command? I don't know if scripts can call API functions... you'd have to declare an external function in kernel32.dll (or wherever it is...).

This will call the "Open" shell command on the URL. Technically, your open command SHOULD point to whatever web browser you use, and therefore it will open your URL. Only thing to be careful of is that it might open your URL in an existing window, which can be annoying sometimes. (At least, IE does that from time to time.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #8 on Tue 30 Sep 2003 05:46 PM (UTC)
Message
If using the InetCtls control works, what is with all these other suggestions? lol Are we trying to find as many solutions as possible?

As for yours Ksilyan, that would work in Visual Basic or some other compiled language where linking such things is possible, but I haven't seen anything like it is scripting. Well... Maybe under IE, but IE uses its own unique COM interface that lets you reference objects by GUID. This is very non-standard, far less safe than CreateObject, which can only use those apps already on your system, and probably still won't work for libraries of that sort. Python could do it, but that is because it comes with Win32 and Win32Com wrappers that impliment those functions.

It is also redundant and overkill imho. He doesn't need to 'see' the page, just load it. For that the InetCtls should be more than sufficient. Same goes for using Mushclient itself to force a read of the document by adding the HTTP stuff to the connection. I find it slightly strange that it works, but... It would be useful for the trick I had above, where I actually need to see the contents and find something in them, but still overkill. An interesting trick though...
Top

Posted by Jeffrey F. Pia   (49 posts)  Bio
Date Reply #9 on Fri 03 Oct 2003 03:32 AM (UTC)

Amended on Fri 03 Oct 2003 04:46 AM (UTC) by Jeffrey F. Pia

Message
Just to give a little background: my router uses a web GUI. When I change settings, the last thing I do is click on a link to "Save ane Reboot Router". I found that if I bookmarked this link, I could remotely reboot my router instead of unplugging it and forcing a cold reboot.

Okay, I tried the first solution using the InetCtls object and I got this error:
Quote:

Error number: -2146827859
Event: Execution of line 1 column 3
Description: ActiveX component can't create object: 'InetCtls.Inet'
Line in error:

Called by: Immediate execution

I also could not get
set ie = createobject("ie.application")
to work for the same reason. Anyone know what could cause this?

I then tried Nick's solution and got the following result:
HTTP/1.1 200 OK
Server: Virata-EmWeb/R5_3_2
Content-Length: 329
Content-Type: text/html
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Last-Modified: Thu, 08 Nov 2001 02:48:38 GMT
Cache-Control: no-cache
Pragma: no-cache

<HTML><HEAD><TITLE>Actiontec</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function do_submit()
{
        frames[1].document.myform.submit();
}
</script> 
</HEAD>
<frameset cols="100%,*" onload="do_submit()">
<frame src="custom_setup_congrats_real.html" name="realpage">
<frame src="savetoflash_hide.html" name="hidepage">
</frameset>
</HTML>

Apparently it runs a function triggering the reboot as soon as the page loads in a browser, but does not when loaded in MC. Is it possible to simulate this via VBScript?
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #10 on Fri 03 Oct 2003 06:52 AM (UTC)
Message
Hmm. The first problem is due to Inet being missing. This is probably a DLL related to the Visual Basic 6 I have installed. It means that the DLL is literally not installed on your machine or that it at least cannot be found. This is not a big surprise, since the needed DLLs are likely incorperated into the install for such programs or direct linked into the executable. I assumed it was a common component though. :(

The second issue with IE is my fault. It is "InternetExplorer.Application" to use it, not "IE.application". It helps to use the right name for some reason. ;) lol

The command set for it includes:

.Navigate "String" - Your URL.
.Visible = Boolean
.FullScreen = Boolean
.MenuBar = Boolean
.Toolbar = Boolean
.Statusbar = Boolean
.Quit
.GoBack
.GoForeward
.StatusText = String

Maybe also available, but I got these off of the WebBrowser control, which is technically the IE 'core' funtions:

.GoHome
.GoSearch
.Refresh
.Stop
.SetFocus
.Top
.Left
.Width
.Height

and anything else that they added since the version of IE that existed whenever the VB 5.0 book I got came out.

As for the last issue. You are incorrect about how the GET HTTP thing work Nick. I tried it with a real page and got a 302. In other words, the GET command recieves an error code. In the case of 302, you get the default 'It worked, I found this page' error result. A real browser apparently then executes some other sort of command, possibly another GET or something different, that retrieves the actually page contents.

In the case of my test I got a 302 page with a redirect, but since Mushclient obviously has no clue what to do with the 302 message or the redirect it did nothing else. Trying to use it to access the router apparently results in a similar failure, since Mushclient can't redirect to the needed page(s) to do the real work.
Top

Posted by Ian Kirker   (30 posts)  Bio
Date Reply #11 on Fri 03 Oct 2003 10:39 AM (UTC)
Message
Just for future reference, I believe this:

dim Shell
set Shell = CreateObject ("Wscript.Shell")
Shell.Run ("<thing>")

provides pretty much the same functionality as the ShellExecute function...
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #12 on Fri 03 Oct 2003 12:09 PM (UTC)
Message
Ah, great, I have been looking for that for some time... Thanks man :p

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Jeffrey F. Pia   (49 posts)  Bio
Date Reply #13 on Thu 09 Oct 2003 10:49 PM (UTC)

Amended on Thu 09 Oct 2003 10:53 PM (UTC) by Jeffrey F. Pia

Message
Thanks for the tip Shadowfyr, I got this snip of code to work:

  Dim IE
  Set IE = createobject("InternetExplorer.Application")
  IE.Visible = True
  IE.Navigate "<url>"
'  Set IE = Nothing
  world.note "Rebooting Router... please stand by."


Interestingly, the router would not reboot if I set IE = Nothing , so I had to comment that out. I wonder if this means I have x number of IE instances running in the background from all the testing I did... heh :) I should probably reboot more often.
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #14 on Fri 10 Oct 2003 12:26 AM (UTC)

Amended on Fri 10 Oct 2003 12:29 AM (UTC) by Shadowfyr

Message
Actually. IE acts as and ActiveX, so when you 'Set IE = Nothing' you kill the instance of the ActiveX control that you are using and that causes the control to close the browser window, probably before it has a chance to execute all of the steps needed to reboot the router.

A better way would be to place the IE variable outside of the subs (making it global), then do this instead:
if IE <> "IWebBrowser2" then
  Set IE = createobject("InternetExplorer.Application")
  IE.Visible = True
end if
IE.Navigate "<url>"
world.note "Rebooting Router... please stand by."
This way the instance of IE you are using will always remain open unless A) you reload the script, B) you close it manually or B) you close the world (or Mushclient). If you do lose the connection, then it will automatically create a new one. ;)

You may want to verify that it will always be "IWebBrowser2" though. This seems a real odd type name, so it might do "IWebBrowser2", "IWebBrowser3", etc. I have no idea. It may work to just check to make sure it isn't "" or Empty.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


90,539 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.