Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

checking internet connection

hi guys,
 i need to check whether the internet connection is available or not.i tried RAS APi and some method.but none of them are not reliable.
is there any alternative method for that one...
thx in advance
regards
prakash
0
vjayaprasen
Asked:
vjayaprasen
  • 2
  • 2
1 Solution
 
jhanceCommented:
There is no such thing as an "internet connection".  The internet is a concept not a thing to be connected to.

What you are therefore asking is impossible to answer.

What I THINK you are asking, but am somewhat unsure due to the ambiguity in your question is:

"How do I know if my computer is actively connected to some network that can reach a remote host?"

If that is really your question then I have some suggestions.  But how to proceed depends on HOW you connect your computer to a network.  There are TWO basic ways:

1) DIAL UP (in Windows terminology, RAS)

2) Wired (or WIRELESS) LAN

Any other type you think you have really is based on one of these two.

1) If you are interested in RAS, the RAS API will tell you EVERYTHING you need to know about the specific RAS connection.  What is will NOT tell you is whether or not you can connect to some remote host.  The ONLY way to know that is to TRY IT.  If it works, the answer is YES, if it fails the answer is NO.  Got it?

2) If you are interested in LAN, there is not a GENERAL Windows API for this.  Different versions of Windows have different capabilities.  So without knowing your platform, I can't give you any specific advice other than to first determine if you are operating in RAS connection.  If not, then a LAN connection is possible.  To determine if you can connect to a remote host or not, use the SAME method as with RAS.  TRY the connection and see if it works.

Keep in mind that even if the connection works NOW, it may NOT work later.  Networks are funny things and they come and go as they please.  So if you are building some application that depends on some sort of network connection, you MUST employ coding practices that anticipate network failure at ANY TIME.  To do otherwise will make your application unstable and very annoying to your users.

If I've misinterpreted your question, please clarify yourself.
0
 
martynjpearsonCommented:
You might want to check out the API functions InternetGetConnectedState() or InternetCheckConnection(). See
http://msdn.microsoft.com/library/en-us/wininet/wininet/internetgetconnectedstate.asp
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetcheckconnection.asp

Hope this helps
Martyn
0
 
jhanceCommented:
Martyn,

You may want to study what these APIs actually do before recommending them in a situation like this...
0
 
martynjpearsonCommented:
I have to admit my suggestion about using InternetGetConnectedState() was based on some research I did onto the problem when wishing to do something similar in one of my own applications, rather than actual experience. I've had a hunt and found the document I found when looking into the problem before :

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q242/5/58.ASP&NoWebContent=1

It describes the use of the function, however, the article does say exactly what you said above - the only way to be sure there is a connection is to try and use it.

Best regards
Martyn
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now