Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Network Adapter Address 1

Status
Not open for further replies.

rgbean

Programmer
Nov 9, 2000
5,707
0
0
US
I've been unable to find any way to reliably get the current Adapter address. While under NT I find it appears in the registry (although it's not straight forward), the technique doesn't work under Win 95/98.
e.g.
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\N1001\Parameters]
"ProposeQNFTAddress"="0008C7DF8B6E"

While I could run IPCONFIG.EXE /ALL > c:\IPCONFIG.TXT in a DOS window and parse out the information, this seems like a quite inelegant solution, and this code is obviously getting it from somewhere.

It was suggested that I create a GUID, and parse off the end. Unfortunately the GUID uses what's known as the Default User ID, which is the MAC address for the Network card when the registry is first created. If you switch network cards (or are working with a "ghosted" machine), the GUID includes the original address rather than the current one (which is of course what I need!).

Rick
 
Hi Rick,
Not quit sure as I didn't do this befor, but I think the system information control can return this value to you if you ready to spend some time with it.There is a sample code for this control in Tastrade application in FoxPro, run the application then Help-> about-> System Info
Hope this is the right way Walid Magd
Engwam@Hotmail.com
 
Unfortunately this isn't a control, but just another MS program that is "RUN /n ...". There doesn't appear to be any obvious way to programmatically get the information I require.

Rick
 
Howdy Rick,

Here are my countless thoughts:

1. I think Walid was refering to the SysInfo ActiveX control. Look in the ActiveX listing for Microsoft SysInfo Control. AFAIK, it doesnt expose the NIC address.

2. IRT the MAC Address being established when the registry is first created, have you tried IPCONFIG /renew_all prior to creating the GUID and extracting the MAC Address? Dont think this would help if you workin with a ghosted machine though.

3. Two years ago I worked with a company the used a 3rd party utility called NetLib. Pretty sweet IP functions. It was capable of querying the NIC address. The only complaint I had was the lack of quality support and a weak KB. I just took a peek at their website and it looks like things have improved. The utility I speak of is at: Comes with a hefty price tag of $1495, but I did notice they have integrated RAS functionality. I also notice you receive a 10% discount for being a PUTM at UniversalThread. Those savings would recompensate for what a PUTM membership costs.

4. A colleague said to look into wwIPStuff @ But I dont recall it having the ability to query the NIC address. He said he recollected it did. Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Thanks Jon,

1. You're right, I hadn't thought about the .OCX. But as you suggested it didn't have anything useful anyway. (Amazing how the obvious is obscured by what you perceive as a wrong lead!)

2. That seems to have "fixed" my Win98 machine (upgraded from Win95). Now I'll have to check a couple of the ghosted machines - but it does show promise.

3. I used NetLib back in the 2.5/2.6 days, but I'll wait on this until I see if #2 fixes my problem.

4. I checked out wwIPStuff, and it doesn't seem to have any NIC (MAC) info available.

Here's hoping idea number 2 is the real solution.

Rick

 
Hi RgBean,
If you have MSDN, pls search for "VB4WIN vb5all vb5howto VBKBNet VBKBWinAPI"

It will show you how to get adapter address in VB,
convert it into VFP!.

Jimmy Jimmy Le
nhan_tiags@yahoo.com
 
Jimmy,

Your search cryterion: "VB4WIN vb5all vb5howto VBKBNet VBKBWinAPI" yields no results.

For future reference, post either the KB article title(which is at the top of the article in bold) or the KB article number(which can be obtained by right clicking in the article body and selecting properties. It will resemble Q999999) Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
How's this article: (of course, this requires structures, so to convert to VFP you'd need to emulate structures, for this see )

HOWTO: Get the MAC Address for an Ethernet Adapter
ID: Q118623

Sample Code

#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

typedef struct _ASTAT_
{

ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];

}ASTAT, * PASTAT;

ASTAT Adapter;

void main (void)
{
NCB Ncb;
UCHAR uRetCode;
char NetName[50];
LANA_ENUM lenum;
int i;

memset( &Ncb, 0, sizeof(Ncb) );
Ncb.ncb_command = NCBENUM;
Ncb.ncb_buffer = (UCHAR *)&lenum;
Ncb.ncb_length = sizeof(lenum);
uRetCode = Netbios( &Ncb );
printf( &quot;The NCBENUM return code is: 0x%x \n&quot;, uRetCode );

for(i=0; i < lenum.length ;i++)
{
memset( &Ncb, 0, sizeof(Ncb) );
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = lenum.lana;

uRetCode = Netbios( &Ncb );
printf( &quot;The NCBRESET on LANA %d return code is: 0x%x \n&quot;,
lenum.lana, uRetCode );

memset( &Ncb, 0, sizeof (Ncb) );
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = lenum.lana;

strcpy( Ncb.ncb_callname, &quot;* &quot; );
Ncb.ncb_buffer = (char *) &Adapter;
Ncb.ncb_length = sizeof(Adapter);

uRetCode = Netbios( &Ncb );
printf( &quot;The NCBASTAT on LANA %d return code is: 0x%x \n&quot;,
lenum.lana, uRetCode );
if ( uRetCode == 0 )
{
printf( &quot;The Ethernet Number on LANA %d is:
%02x%02x%02x%02x%02x%02x\n&quot;,
lenum.lana,
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}

}
 
I noticed some of the code got parsed by the TGML stuff, it should be:
Sample Code

#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

typedef struct _ASTAT_
{

ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];

}ASTAT, * PASTAT;

ASTAT Adapter;

void main (void)
{
NCB Ncb;
UCHAR uRetCode;
char NetName[50];
LANA_ENUM lenum;
int i;

memset( &Ncb, 0, sizeof(Ncb) );
Ncb.ncb_command = NCBENUM;
Ncb.ncb_buffer = (UCHAR *)&lenum;
Ncb.ncb_length = sizeof(lenum);
uRetCode = Netbios( &Ncb );
printf( &quot;The NCBENUM return code is: 0x%x \n&quot;, uRetCode );

for(i=0; i < lenum.length ;i++)
{
memset( &Ncb, 0, sizeof(Ncb) );
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = lenum.lana;

uRetCode = Netbios( &Ncb );
printf( &quot;The NCBRESET on LANA %d return code is: 0x%x \n&quot;,
lenum.lana, uRetCode );

memset( &Ncb, 0, sizeof (Ncb) );
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = lenum.lana;

strcpy( Ncb.ncb_callname, &quot;* &quot; );
Ncb.ncb_buffer = (char *) &Adapter;
Ncb.ncb_length = sizeof(Adapter);

uRetCode = Netbios( &Ncb );
printf( &quot;The NCBASTAT on LANA %d return code is: 0x%x \n&quot;,
lenum.lana, uRetCode );
if ( uRetCode == 0 )
{
printf( &quot;The Ethernet Number on LANA %d is:
%02x%02x%02x%02x%02x%02x\n&quot;,
lenum.lana,
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top