2

How can I check through my application if computer is connected with internet or not (at the moment) I need a message if net is connected.

Thanks a lot Furqan

2
  • If the internet is connected what will you do next? Once we know the answer to what comes next, then we can provide the best answer. Commented Aug 19, 2010 at 13:04
  • I would initiate the application to send an email if internet is found connected. Commented Aug 20, 2010 at 17:29

4 Answers 4

4

ping. Dim response As Boolean = False response = My.Computer.Network.ping(google.com)

True, you have access, false, you don't, or the world is ending because google is offline.

Sign up to request clarification or add additional context in comments.

1 Comment

Or google have shut down ICMP replies in response to Ping flooding attacks
3

I would try that. It's from VB 6, but I think you can easily convert it.

Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef
dwflags As Long, ByVal dwReserved As Long) As Long

Public Function IsOnline() As Boolean
Dim LFlags As Long
IsOnline = InternetGetConnectedState(LFlags, 0&)
End Function

http://bytes.com/topic/visual-basic/answers/14551-detecting-internet-connection

1 Comment

This looks a bit better. Same idea anyway. This is surely the best answer. What if Google dies. I don't like the accepted answer. I haven't checked but I assume that probably ping consumes more performance as well.
2

Internet connectivity should be handled similar to file availability.

With files, you should typically not use File.Exists() to first see if you can open a file because the results might change on you between when you perform the check and when you act on the results, let alone the difference between mere existence and read permissions. You have to handle the exceptions anyway, and so that's really a better place to concentrate your efforts.

The same is true for internet access. The best option is generally to just go and do it, and concentrate your development time on your exception handler.

Comments

0

Use this code :

If My.Computer.Network.IsAvailable Then
    MsgBox("Computer is connected.")
Else
    MsgBox("Computer is not connected.")
End If

Refer to this link.

1 Comment

The problem I've had with this is that there can be false positives due to virtual adapters, ie. it appears to detect my VMware virtual adapters & thinks my PC has network access even when I've unplugged from any network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.