...

View Full Version : Trying to call cmd.exe from JS



Puddin
11-14-2012, 05:53 AM
I'm still kind of a noob to Javascript so I may be out of my league here but I'm trying to run a ping from a button through XML. I can't even get a command prompt to open much less run the ping

Here is my function


onToolbarpingerCommand: function(e) {

var objShell = new ActiveXObject("Shell.Application");
objShell.ShellExecute("cmd.exe", "ping" + "192.168.0.1");
}


I'm still learning so please don't write all the code for me. (unless it is an easy mistake :P ) I'm simply looking for guidance on what I'm doing wrong.

Puddin
11-14-2012, 06:53 AM
I have been searching around and also found it done like this.


onToolbarpingerCommand: function(e) {

var run=new ActiveXObject('WSCRIPT.Shell').Run("cmd.exe", "ping" + "192.168.0.1");
}


Has about the same amount of functionality for me though :(

AndrewGSW
11-14-2012, 07:48 AM
I haven't played with your code but three obvious things:

it will only work in IE
you need a space after "ping"
are you calling the function?

Puddin
11-14-2012, 08:03 AM
Thanks for the reply :)

Sorry as I said I'm fairly new Why would it only work in IE? Bad part is that this is a part of a firefox extension :( . That could be my whole issue.

The space for the ping I thought would be in place due to the double quotes. Either way I cannot even get the prompt to open for the ping to be placed.

I am calling the function with a button in XUL as outlined below


<toolbarbutton id="customer_direct_helper-toolbar-pinger"
tooltiptext="&customer_direct_helperToolbarpinger.tooltip;"
label="&customer_direct_helperToolbarpinger.label;" oncommand="customer_direct_helper.onToolbarpingerCommand()" />

AndrewGSW
11-14-2012, 11:43 AM
objShell.ShellExecute("cmd.exe", "ping 192.168.0.1");

.. but ActiveXObject is an IE-only object.

I am unable to advise further, sorry :thumbsup:

Added: Is ping useful anyway, if you are unable to check its response..

Pingler (https://addons.mozilla.org/en-us/firefox/addon/pingler/)

rnd me
11-14-2012, 11:58 AM
function ping(ip) {
clearTimeout(ping.timer);
var i = ping.i || (ping.i = new Image);
i.src = "http://"+url;
ping.timer = setTimeout(function() {
i.src = "";
}, 9999 );
} /* end ping() */

usage:

ping ("192.168.0.1")

AndrewGSW
11-14-2012, 12:16 PM
@rnd me: Thank you.

A little search tells me that ping-ing notifies a server of changes to a web page (or site).

This seems (to me) to be almost accidental, as it's original purpose - from the command line - was to test a connection, receiving a detailed response. I gather that the response itself is usually ignored, as simply receiving any response is sufficient to confirm the connection as 'active'.

rnd me
11-14-2012, 12:25 PM
@rnd me: Thank you.

A little search tells me that ping-ing notifies a server of changes to a web page (or site).

This seems (to me) to be almost accidental, as it's original purpose - from the command line - was to test a connection, receiving a detailed response. I gather that the response itself is usually ignored, as simply receiving any response is sufficient to confirm the connection as 'active'.

no, this simply tries to load the front page of the IP address, regardless of if it changed or not. you won't get any feedback in js with the above script, though the site can feel it.

if the site is not one you control, it's more difficult to tell exactly what's going on with its content, or even if it's online.

one "hack" is using a known image url to see if the site is online. you load an image at the url and wait to see if the load() or error() fires. if error() fires, the server is offline.

if the server emits access-control headers, you can use ajax to fetch the url and inspect the content for changes yourself.


finally, it is VERY practical and possible to use "timing attacks" and error messages to determine if a site is on or offline. various incarnations of this use hidden iframe load events, img ping timeouts, and certain subtle differences in some javascript-reported URL-based error messages between status 200, 404, and no response at all. i won't go into details here, but the info is out there if you need it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum