?
Solved

Detecting Network Connection?

Posted on 2003-03-18
9
Medium Priority
?
214 Views
Last Modified: 2013-11-20
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??
0
Comment
Question by:string6
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8161097

  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.


0
 

Author Comment

by:string6
ID: 8161196
Is that the only way?
Is there any way using MFC or Win32 API????
0
 
LVL 1

Expert Comment

by:ice911
ID: 8164151
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 8164826
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
0
 

Author Comment

by:string6
ID: 8169257
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
 
0
 

Author Comment

by:string6
ID: 8169343
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.
0
 
LVL 1

Accepted Solution

by:
ice911 earned 1200 total points
ID: 8171306
ok!!
when you connect a computer to a network that computer starts to get sent broadcasts to check the connection of the computers in the network.

That means packets are being sent to the connected interface and no packets being sent to a non-connected interface.

So you can you iphlpapi.h to find out if packets are being sent to the interface/nic card and if so the cable is definitely connected and if not, not connected.

here's some algorithm for you.

p.s. this is probably how windows xp checks for disconnected cables, if no data then no connection.
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8211951

 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.
0
 

Author Comment

by:string6
ID: 8212303
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"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Loops Section Overview
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question