Link to home
Start Free TrialLog in
Avatar of string6
string6

asked on

Detecting Network Connection?

How can I detect is network cable is plugged  in to the network card?

I am trying to write code that notify when the network cable is plugged back.

For example, this sofware waits until the network card is plugged.  When the user plug it to the NIC it should automatically talk to a remote comupter using UDP.

ANY Idea??
Avatar of williamcampbell
williamcampbell
Flag of United States of America image


  I think you might have to write a MiniPort Driver

 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/network/hh/network/205mpinfo_0tlz.asp

  The MinPort Driver could Set a Named Event when the cable is connecsted or disconnected. Your app could WaitForSingleObject on the Named event.

  Requires getting the DDK.


Avatar of string6
string6

ASKER

Is that the only way?
Is there any way using MFC or Win32 API????
You could send an ICMP packet to check if you are connected to any other host ( basically ping the other computer) and if the ICMP packet checks out ok then you can send your udp packets.

cable not plugged in is basically the same as a computer disconnect from another computer so this should be good enough.

-ice911

just adding some input
You can Use the API IsNetworkAlive

Determines whether the local system is connected to a network and the type of network connection, for example, LAN, WAN, or both.



Good Luck
Avatar of string6

ASKER

I tried to use IsNetworkAlive() ,

It DOES NOT WORK!!!

I unplugged my len cable and I call that function.
Guess what, it returns TRUE!!!!

Not only it returns true, but also it sets the NETWORK_ALIVE_LAN bit to TURE!!!

Does anyone have any idea????

This is driving me crzy!!!!!!!!!11
 
Avatar of string6

ASKER

to ice911

I cannot use that function, because the detaction of the connection should not care about other computer.  It really have to just know if the computer is connected to a network.
ASKER CERTIFIED SOLUTION
Avatar of ice911
ice911

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

 I was interested in the answer to this question but the answer above makes no sense to me, can you print what you did as others might be interested too.
Avatar of string6

ASKER

Well, I did not use te posting.

Actually, I did not get the answer I was looking for.
However, I decided to give the credit who gave me most postings.

What I did to solve this problem was stupid.

I wanted to something fency like you said, but the time was running out.  So I had to use whatever it works.

I send a samll UDP data to myself.  Eve thought the destination of the data is the same as origination, the UDP data have go out and and come back in.  Thus, if your computer is connected (plugged) to the network the data  wll come back, if not it does not come back. In this way, the software I am writing does not have to know anything about other computers on the network.

I think this is very stupid solution, but I have to do whatever I have to do now.  If you have better suggestion, please let me know.  I will love to solve this problem in more "Proffesional way"