Script to check internet conectivity

Anyone have any suggestions for a simple way to check internet connectivity?
Am wanting to build in ‘debug’ in to my api script.
At the minute the first part of my script checks if the json api request response against the response from last request which is saved in a program setting.
My next check (else if) will be if first 15 characters of response are ’ [{"booking_id": ’ which will be a ‘good’ response.

If it is not then there will be one of a few possibilities most likely being internet connection issue.
My next step will be to run a basic auth_test to test there isnt an issue with API, as that has a static response I can easily validate it. If this fails there will be problem with the PMS system and will log the response and ideally email me/hotel with the response also

A draft of the if structure would be as follows;

if (response begins ["booking_id":)
	{
		if (responce == same as last time)
			{
			LOG NO UPDATE NEEDED
			} else {
			UPDTE & LOG CHANGES
			}

	} else if (auth_test == know good response) 
		{
		
		//PMS is working, internet is working, must be issue with update request
		EMAIL RESPONCE OF UPDATE REQUEST & LOG
	

	} else if (check internet == WORKING) {
		
		//Update response IS NOT GOOD && AUTH TEST IS NOT GOOD
		//Internet is WORKING so issue is with PMS system/script
		LOG RESPONCE TO REQUEST & AUTH TEST & EMAIL THEM TOO

	} else {	
		
		//Internet is down, update script log with internet down
		LOG INTERNET DOWN & NO OTHER ACTION
        }

If I were testing a PC the usual method would be to ping google DNS but cant find clear code for that.
Did see a suggestion of trying to download a file but not sure how I can validate that…

Any suggestions?

To be able to ping an ip address would be awesome as could also then create my own Wifi checker :smile: curently use a ping tester to ping all the wifi boxes and network in the hotel, as guest wifi is provided through over 12 access points occasionally they need a reboot however (especially the more remote ones which are not in the main part of the building) some go down and although we have the ping tester it obviously needs to be checked, have tried using the email function in the software however if a box stops responding it continuiously emails again and again each time it fails (is set to check every 60 minutes) but if could program my own script could set to only email once each day or something, either way thats secondary, the integration internet connectivity check is more important for now.

This was the image download sugestion;

function ping(extServer){
 var ImageObject = new Image();
 ImageObject.src = "http://"+extServer+"/URL/to-a-known-image.jpg"; //e.g. logo -- mind the caching, maybe use a dynamic querystring
 if(ImageObject.height>0){
   alert("Ping worked!");
 } else {
   alert("Ping failed :(");
 }

}

Not tried yet though…

function test(){
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("cmd /c ping 127.0.0.1 > C:\\Users\\JTR\\Desktop\\Pinglog.txt"   );


while (oExec.Status == 0)
{
     WScript.Sleep(100);
}

WScript.Echo(oExec.Status);
}

This seems to work from within samba :smile: although outputs to text file.

1 Like

But cant see a way to directly read the response, guess it would be the case of reading the test file it produces :-?

Plus i get WScript is undefined…

Probably because you defined the object as WshShell, not WScript.

I didnt write that :stuck_out_tongue:

Changing it to WshShell gives object doesnt support that method…

You could have permissions issues with WSH, in that by default, it requires elevated privileges (Admin).

function test(){
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("cmd /c ping 8.8.8.8 > C:\\Users\\JTR\\Desktop\\Pinglog.txt"   );
}

works on its own, presume the other but was a retry.

annoying thing is it leaves a cmd windows open EVERY time its run…

I am admin user and the WshShell.Exec works…

Reading ping responce shouldnt from text shouldnt be to bad so long as can trim lines, if not so long as response times stay between 10-99ms the layout should be similar up to % loss (0-100)

I seem to remember that @emre gave us the ability to read return values of program execution. I need to find that post.

Also, recent enhancements to file.X() helper in latest .57 refresh added an execute function…

file.For('c:\\folder\\test.txt').Starter().Execute();

The new ones were for folder creation I think…

file.ReadFromFile()

But if we could read directly from cmd exe that would be sweeeeet.

function test(){
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("cmd /c ping 8.8.8.8 > C:\\Pinglog.txt");
var listFile = file.ReadFromFile("C:\\Pinglog.txt");
var listLine	= listFile.split('\n')
return listLine[7];
}

kinda works but need to delay the read file as ping obviously takes time…

Google responses all relate to delaying whole function.

I guess this isn’t new at all - it was added in .52 …

file.Starter(<filePath>).Execute();
file.Starter(<filePath>).Hidden.Execute();
file.Starter(<filePath>).With(<arguments>).Execute();
file.Starter(<filePath>).WorkOn(<workingDir>).Execute();
var returnVal = file.Starter(<filePath>).With(<arguments>).WorkOn(<workingDir>).Hidden.ShellExecute();
1 Like

Hmm, am struggling to use;
var returnVal = file.Starter(<filePath>).With(<arguments>).WorkOn(<workingDir>).Hidden.ShellExecute();

Not sure on the definitions of the parameters;

function test(){
var response = file.Starter("C:\\Pinglog.txt").With("cmd /c ping 8.8.8.8 > C:\\Pinglog.txt").WorkOn("C:\\").Hidden.ShellExecute();
return response
}

If giving a samba complete freeze

FilePath is the path/file to the executable. Using ShellExecute() you should even be able to set the file to .htm to launch Browser, .txt to launch Notepad, etc…

1 Like
function test(){
var response = file.Starter("C:\\Windows\\System32\\cmd.exe").With("ping 8.8.8.8").Hidden.ShellExecute();
return response
}

Thanks, makes seance, am still struggling though, above still gives faital samba freeze.

Take out Hidden.

SambaPOS is waiting for the command window to be closed to return a value. Once you close the window, the return is generated.

Once you get it working properly and the window can close on its own, you should be able to put Hidden back in.

1 Like

Ok thanks, great.

With("ping 8.8.8.8")
obviously isnt the what cmd to run.

where does the pin command go?

Not sure. Have not been able to get ping to work yet.

function exec() {
  var p = 'C:\\Windows\\System32\\';
  var f = 'cmd.exe';
  var args = '/c ping 8.8.8.8 > C:\\Pinglog.txt';
  var wdir = 'C:\\';
  var returnVal = file.Starter(p+f).With(args).WorkOn(wdir).ShellExecute();
  return 'rv:'+returnVal;
}

I expected that to work, but it does not. And theoretically, we should be able able to call ping directly, without cmd.exe. Though I suppose we need CMD functionality to redirect ping output to file.

1 Like