Retrieve connection time to wireless adapter

424 views Asked by At

I write because I could not find any answers on the internet. I am writing a project in C# on WLANs (using managed C++). Considering a given interface (network card) connected to a network, there is a way to know how long the interface is connected to the network?

In other words, I would like to know the time that you see in the connection information in Windows 7 (trayicon -> Open Network and Sharing Center).

I hope I was clear and I apologize for my poor English.

http://imageshack.us/photo/my-images/39/immaginenrz.png/

1

There are 1 answers

8
Murtuza Kabul On

May be you are looking for getiftable() function of windows. It is a winapi function that provides all the information related to a particular network interface

Here is a good example of it

Here is the explanation of the entire structure

According to msdn

dwLastChange

Type: DWORD

The length of time, in hundredths of seconds (10^-2 sec), starting from the last computer restart, when the interface entered its current operational state.

When connected, it will give you the time since it is so - i.e. in connected state.

Here is the declaration of this function in c#

public static extern uint GetIfTable(IntPtr pIfTable, ref uint pdwSize, bool bOrder);

Declare Function GetIfTable Lib "iphlpapi.dll" (TODO) As TODO

        IPHelperTraslation.GetIfTable(IntPtr.Zero, ref size, false);

        IPHelperTraslation.GetIfTable(buf, ref size, false);

You can use pinvoke.net for further help on declaration.

It seems like there is an easy way in .Net framework but not as expected

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.operationalstatus.aspx

Check out the way they have implemented network status detection. My assumption is, you will have to record the time in your application since the status last changed.

I also practically tested the getifrow function and to my disappointment, it always returns zero on Win7, don't know about other platforms.