Quantcast
Channel: SambaClub Forum - Latest topics
Viewing all articles
Browse latest Browse all 8861

Tutorial: Internet connectivity check

$
0
0

@JTRTech wrote:

Anyone using online services may find this useful.

Have been working on an integration with cloud based service and wanted an internet connectivity test script as part of my system to check against should the expected response not be returned to see if it was internet issue, script issue or cloud service issue.

Anyway, this script will ping 8.8.8.8 (google dns server) to check internet connectivity.
Using the response you can diagnose the api response issue within the script (handy for logs)

function internetCheck() {
	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).Hidden.ShellExecute();
	var listFile		= file.ReadFromFile("C:\\Pinglog.txt");
	var listLine		= listFile.split('\n')
	var packetLoss	= listLine[8].substr(47,58-listLine[8].length);
	if 	(packetLoss == 0)
		{
		var response = 'OK';
		} else if (packetLoss == 100) {
		var response = 'Down';
		} else {
		var response = 'Issues';
		}
	return 'Internet Conectivity "'+response+'"';
}

Will return one of the following;
1. Internet Connectivity "OK"
2. Internet Connectivity "Down"
3. Internet Connectivity "Issues"

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 8861

Trending Articles