How To Find Network Connection exists or not?

vinidel

Member
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 dont know what is wrong or may be its a bug.

Do let me know if anyone can think of something else.
 
There isnt a "correct" method. Theres no way for an OS to determine conditions beyond the NIC or modem. Try connecting to a resource. If the connection completes youre connected. If it doesnt... well... there isnt a usable connection.
 
hey guys im completely new to .net but i remember in VB6 there was an api InternetGetConnectedState that did check for connection
:confused:
i dont 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("Im 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