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 Mike Lewis 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 user is connected

Internet Connection

How to know if user is connected

by  craigsboyd  Posted    (Edited  )
This is one of the most reliable ways to do this. Some other methods can provide erroneous results if the user's machine is hooked up to a network. You can replace the IP I have used with one of your own, especially if the reason you are checking the connection is to see if the user can get to your FTP site of Website you should use that IP instead, because sometimes you not only want to know if the user has an internet connection but also can they get to your site.

Code:
DECLARE INTEGER GetRTTAndHopCount IN Iphlpapi;
	INTEGER DestIpAddress, LONG @HopCount,;
	INTEGER MaxHops, LONG @RTT

DECLARE INTEGER inet_addr IN ws2_32 STRING cp

LOCAL lnDst, lnHop, lnRTT
lnDst = inet_addr("216.109.117.108") && Yahoo IP, replace with your own IP address if you don't want reliance on yahoo
STORE 0 TO lnHop, lnRTT

IF GetRTTAndHopCount(lnDst, @lnHop, 50, @lnRTT) = 0
	MESSAGEBOX("You are not currently connected to the internet.")
ELSE
	MESSAGEBOX("You are connected to the internet.")
ENDIF
CLEAR DLLS GetRTTAndHopCount, inet_addr
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top