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 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.
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 :(");
}
}
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…
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)
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.
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…
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.