How To Find Network Connection exists or not?

vinidel

Newcomer
Joined
Jan 8, 2004
Messages
7
Hi All,
I tried systeminformation.network, but its returning true in both the cases.
I unhooked my laptop from docking station and tried with detaching the network cable also, still it SystemInformation.Network returns TRUE.

I don't know what is wrong or may be its a bug.

Do let me know if anyone can think of something else.
 
There isn't a "correct" method. There's no way for an OS to determine conditions beyond the NIC or modem. Try connecting to a resource. If the connection completes you're connected. If it doesn't... well... there isn't a usable connection.
 
hey guys i'm completely new to .net but i remember in VB6 there was an api InternetGetConnectedState that did check for connection
:confused:
i don't even know if you still can use apis in .net
 
:)

Yes, it is very possible to determine the connection. Here is how..


Private Declare Function InternetGetConnectedState Lib "wininet" _
(ByRef dwflags as long, ByVal dwReserved as Long) as Long

'Define types of connections
Private Enum ConnectStates
Lan=&H2
Modem=&H1
Proxy=&H4
Offline=&H20
Configured=&H40
RasInstalled=&H10
End Num

Public Sub Main()
dim dwFlags as Long
Dim Connected as boolean = _
(InternetGetConnectedState(dwFlags,0&) <> 0 )

If Connected Then
Console.writeline("I'm connected to the internet.")
Console.write("Connection flags:")

Dim ConnectionType as ConnectStates
For each connectiontype In_
System.Enum.GetValues(GetType(ConnectStates))
If (ConnectionType And dwFlags) = ConnectionType Then
Console.write(" " & ConnectionType.tostring())
End If
Next
End If

Console.ReadLine()
End Sub

End Module
 
Back
Top