Is laptop connected to LAN?

  • Thread starter Thread starter Chuck
  • Start date Start date
C

Chuck

I am developing an application for use on laptop computers. I need to be
able to programmatically determine if the laptop is connected to the
network. If the connection exists I want to use the database on the
server, otherwise I want to use a cache on the laptop. I do know the
address of a server on the LAN.

The only way I can see is to attempt to use
System.Data.OleDbConnection.Open(), and catch any exceptions it throws when
it can't find the server. I hope one of you can suggest a better answer, as
this one has problems.

At this time remoting to a service is not possible.

Anyone have any ideas?


Thanks
Chuck
 
Here's a draft I just wrote (there are a few typos, but the code is
correct)... http://www.knowdotnet.com/testsite/articles/system_net.html

You can use a HTTP request to verify that you are out. There is a windows
API that tests for connectivity, but it only tells you if you are configured
for it, so it will come back as connected, but if you pull out the network
cable, it will still register as true.

HTH,

Bill
 
Sorry, isn't ping is a stand alone utility? I need to do this automaticly
from within a C# application. I looked, but could not find any functionality
that would ping from within a C# app.

Chuck
 
Hi Chuck,

I have an example but it is in VB.net it, is not mine and and I never
tried it, but Kevin Yu has contributed it once to the VB.net group.

If you want to have it, tell it here, I will look tomorrow and than paste it
in.

Cor
 
Hi Chuck

I hope it helps you.

Cor

\\\by Kevin Yu
Private Const WSADESCRIPTION_LEN = 256

<StructLayout(LayoutKind.Sequential)> _
Public Structure WSADATA

Public wVersion As Short
Dim wHighVersion As Short

<MarshalAs(UnmanagedType.ByValTStr, sizeConst:=WSADESCRIPTION_LEN +
1)> _
Public szDescription As String
<MarshalAs(UnmanagedType.ByValTStr, sizeConst:=WSADESCRIPTION_LEN +
1)> _
Public szSystemStatus As String
Public iMaxSockets As Integer
Public iMaxUdpDg As Integer
Public lpVenderInfo As IntPtr

End Structure

Private Declare Function WSAStartup Lib "wsock32" (ByVal
wVersionRequired As Integer, ByRef lpWSADATA As WSADATA) As Integer

In your codes you can use it as:

Dim Data As New WSADATA
If WSAStartup(&H201, Data) = 0 Then
'Codes of your logic
End If
///
Cor
 
Back
Top