Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to know if I am connected to internet ?

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
TN
Hi !
I wonder if there is a function to detect if i am connected to internet or not in Vbscript?
Thank you !
 
You could have a VB Script ping Google via Shell and check the result.
;-)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
As MakeItSo suggested

Code:
function ping (strComputer)
	ping = false

	set objShell = WScript.CreateObject("WScript.Shell")
	set objExec = objShell.Exec("%comspec% /c ping.exe " & strComputer & " -n 1 -w 100")
	do until objExec.Stdout.AtEndOfStream
		strLine = objExec.StdOut.ReadLine
		if (inStr(strLine, "Reply")) then
			ping = true
			exit function
		end if
	loop
end function

'Usage
if (ping("4.2.2.2")) then
   'Im connected!
else
   'Something's wrong
end if

Any valid web address or IP will work but I like to use one of the global DNS IPs, 4.2.2.2. If that doesn't ping, you are either no connected or the world is experiencing armageddon!

-Geates



"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top