Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-14-2012, 04:53 AM   PM User | #1
Puddin
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Puddin is an unknown quantity at this point
Trying to call cmd.exe from JS

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 is offline   Reply With Quote
Old 11-14-2012, 05:53 AM   PM User | #2
Puddin
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Puddin is an unknown quantity at this point
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
Puddin is offline   Reply With Quote
Old 11-14-2012, 06:48 AM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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?
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 11-14-2012, 07:03 AM   PM User | #4
Puddin
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Puddin is an unknown quantity at this point
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()" />
Puddin is offline   Reply With Quote
Old 11-14-2012, 10:43 AM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Code:
objShell.ShellExecute("cmd.exe", "ping 192.168.0.1");
.. but ActiveXObject is an IE-only object.

I am unable to advise further, sorry

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

Pingler
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 11-14-2012 at 10:51 AM..
AndrewGSW is offline   Reply With Quote
Old 11-14-2012, 10:58 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Code:
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:
Code:
ping ("192.168.0.1")
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 11-14-2012, 11:16 AM   PM User | #7
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
@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'.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 11-14-2012, 11:25 AM   PM User | #8
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by AndrewGSW View Post
@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.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 PM.


Advertisement
Log in to turn off these ads.