News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Checking if LAN is connected to a router

Started by Paulo, August 31, 2013, 01:46:12 AM

Previous topic - Next topic

Paulo

Hi all
I have a win7 machine that has a 3G USB modem and 2 ethernet LAN cards.
What I need to do programatically is to be able to detect if the LAN cards are connected to a router and receiving the ethernet link pulses.
Please note that I am not trying to check for internet connectivity.
My first port of call was to try calls like InternetGetConnectedState but this returns true if any of the LAN cards or 3G modem are connected which is not what I want.
I'm looking for something like in ipconfig where it shows connected media which means for LAN cards are receiving link pulses.
Anyone know what dll to use?
Thanks.

jj2007

Load ipconfig.exe into PEView (section text, import address table) and see what it uses...
dhcpcsvc.dll
dnsapi.dll
iphlpapi.dll
netman.dll
...

Paulo

Hi jj2007
Hang on whilst I slap myself several times for not thinking of using PEview :-)
Thank you.

Vortex

Hi Paulo,

This one should work too :

\masm32\bin\dumpbin.exe /IMPORTS C:\WINDOWS\system32\ipconfig.exe

jj2007

dumpbin is even better for copy & paste :t

Paulo

Tried PEview and dumpbin but alas ipconfig.exe is 64 bit on this machine so not much output from either one.
Not to worry will fire up my XP machine and the ipconfig and the dlls it uses will be 32 bit so can run them thru PEview and dumpbin.

dedndave

for 32-bit, i like an old (and simple) disassembler by Sang Cho
it doesn't even try to disassemble data - and it chokes on newer extensions - lol

but, i like it because it gives you a quick look at what functions are imported

http://hcilab.cju.ac.kr/disasm.html

Paulo

Hi dedndave
I remembered I have URSoft W32 disassembler and debugger on my XP box so ran ipconfig thru that and got the info I needed.
Ipconfig makes use of iphlpapi.dll which has lots of handy exports like GetAdaptorInfo, GetInterfaceInfo and so on.
Thanks for the help guys.

Paulo

update

To get number of network cards, I use iphlpapi.dll and call GetNumberOfInterfaces.
In XP 32bit it returns 4 which is correct as I have one lan card one wifi interface a virtualbox nic interface and of course local host at 127.0.0.1
However in 7 64bit it returns 26, 26? WTF?
All I have on the 7 box is a lan and wifi so it should return 3.
Anyone have any thoughts on this?

sinsi

Go to device manager and view -> show hidden devices.
Lots of them under network adapters.

Paulo

Hi sinsi
Did that and there are only 16 listed not 26 as reported by GetNumberOfInterfaces.