Detecting Network Connection?

Posted on 2003-03-18
Medium Priority
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??
Question by:string6
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
LVL 12

Expert Comment

ID: 8161097

  I think you might have to write a MiniPort Driver


  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.


Author Comment

ID: 8161196
Is that the only way?
Is there any way using MFC or Win32 API????

Expert Comment

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.


just adding some input
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

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

Author Comment

ID: 8169257
I tried to use IsNetworkAlive() ,


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

Author Comment

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.

Accepted Solution

ice911 earned 1200 total points
ID: 8171306
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.
LVL 12

Expert Comment

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.

Author Comment

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"

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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