?
Solved

How Can I Get the MAC Address Of A Network Card ?

Posted on 1999-07-09
12
Medium Priority
?
349 Views
Last Modified: 2010-04-02
Hi,

Is there a simple way to find out the MAC address of a network card for a Windows program ?

Thanks,

James
0
Comment
Question by:James Atkin
[X]
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
  • 5
  • 5
  • 2
12 Comments
 
LVL 4

Author Comment

by:James Atkin
ID: 1263440
Maybe there is an ActiveX control which will supply such info ?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1263441
nbtstat -a name-of-machine
0
 
LVL 11

Expert Comment

by:alexo
ID: 1263442
1) Windows-specific questions should be asked in the windows programming area.
2a) CoCreateGuid()
2b) UuidCreate()


0
Technology Partners: 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!

 
LVL 11

Expert Comment

by:alexo
ID: 1263443
Last bytes of the pointed to value are the MAC address (if there is a NIC, that is...)
0
 
LVL 4

Author Comment

by:James Atkin
ID: 1263444
Sorry, I should have made the question a bit clearer ...

What I am looking for is a function that I can call from within a C program that will return such info.

An ActiveX control would be even easier ... if one existed ?

Thanks again
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1263445
oops, missed that we're in C topic, sorry.
So if all fails, you may use somthing like (just out of memory:)

popen(pipe "nbtstat -a name-of-machine|");
while (fscanf(pipe,"%s")!=eof) {
  /* parse input */
}
close(pipe);
0
 
LVL 11

Accepted Solution

by:
alexo earned 400 total points
ID: 1263446
OK, three solutions:

////////////////////////////////////////////////////////////////////////////////

#pragma warning(disable: 4201 4214 4514)
#include <objbase.h>
#pragma comment(lib, "ole32.lib")

void main()
{
    GUID guid;
    char mac[13]; // <--- MAC address goes here
    CoCreateGuid(&guid);
    wsprintf(mac, "%02X%02X%02X%02X%02X%02X",
             guid.Data4[2], guid.Data4[3], guid.Data4[4],
             guid.Data4[5], guid.Data4[6], guid.Data4[7]);
}

////////////////////////////////////////////////////////////////////////////////

#pragma warning(disable: 4514  4201 4214 4115 4057)
#include <rpc.h>
#pragma comment(lib, "rpcrt4.lib")

void main()
{
    UUID uuid;
    char mac[13]; // <--- MAC address goes here
    char* pBuff;

    UuidCreate(&uuid);
    UuidToString(&uuid, &pBuff);
    lstrcpy(mac, pBuff + 24);
    RpcStringFree(&pBuff);
}

////////////////////////////////////////////////////////////////////////////////

http://support.microsoft.com/support/kb/articles/q118/6/23 .asp

////////////////////////////////////////////////////////////////////////////////

0
 
LVL 4

Author Comment

by:James Atkin
ID: 1263447
That works great !  Thanks !

Is there is an alternative library in Borland C ?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1263448
>> Is there is an alternative library in Borland C ?

Huh?
0
 
LVL 4

Author Comment

by:James Atkin
ID: 1263449
The libraries 'rpcrt4.lib' and 'ole32.lib' appear to be part of Visual C++. This isn't a problem as we can compile as a separate DLL, however, it would be nice to include this into our standard Security Libraries (which are compiled using Borland C)

I tried using the libraries supplied with Visual C in Borland C, but it is having none of it !

I thaught there may be 'equivalent' libraries in BC ?

This is somewhat of a new area to me, so please excuse me if I'm missing something simple !!!

Thanks again,

James
0
 
LVL 11

Expert Comment

by:alexo
ID: 1263450
Those libraries implement the functions CoCreateGuid() and UuidCreate().
I don't know what is the Borland counterpart.

0
 
LVL 4

Author Comment

by:James Atkin
ID: 1263451
Found it !
Borland C contains a library called 'ole2w32.lib'
The function is in there.

Thanks for all the help,

James
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

718 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