The MASM Forum

General => The Campus => Topic started by: Paulo on August 31, 2013, 01:46:12 AM

Title: Checking if LAN is connected to a router
Post by: Paulo on August 31, 2013, 01:46:12 AM
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.
Title: Re: Checking if LAN is connected to a router
Post by: jj2007 on August 31, 2013, 02:09:18 AM
Load ipconfig.exe into PEView (section text, import address table) and see what it uses...
dhcpcsvc.dll
dnsapi.dll
iphlpapi.dll
netman.dll
...
Title: Re: Checking if LAN is connected to a router
Post by: Paulo on August 31, 2013, 02:26:09 AM
Hi jj2007
Hang on whilst I slap myself several times for not thinking of using PEview :-)
Thank you.
Title: Re: Checking if LAN is connected to a router
Post by: Vortex on August 31, 2013, 02:34:03 AM
Hi Paulo,

This one should work too :

\masm32\bin\dumpbin.exe /IMPORTS C:\WINDOWS\system32\ipconfig.exe
Title: Re: Checking if LAN is connected to a router
Post by: jj2007 on August 31, 2013, 02:53:27 AM
dumpbin is even better for copy & paste :t
Title: Re: Checking if LAN is connected to a router
Post by: Paulo on August 31, 2013, 03:00:31 AM
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.
Title: Re: Checking if LAN is connected to a router
Post by: dedndave on August 31, 2013, 05:48:08 AM
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 (http://hcilab.cju.ac.kr/disasm.html)
Title: Re: Checking if LAN is connected to a router
Post by: Paulo on August 31, 2013, 05:39:23 PM
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.
Title: Re: Checking if LAN is connected to a router
Post by: Paulo on August 31, 2013, 07:13:56 PM
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?
Title: Re: Checking if LAN is connected to a router
Post by: sinsi on August 31, 2013, 07:31:51 PM
Go to device manager and view -> show hidden devices.
Lots of them under network adapters.
Title: Re: Checking if LAN is connected to a router
Post by: Paulo on August 31, 2013, 07:41:05 PM
Hi sinsi
Did that and there are only 16 listed not 26 as reported by GetNumberOfInterfaces.