• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

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

Hi,

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

Thanks,

James
0
James Atkin
Asked:
James Atkin
  • 5
  • 5
  • 2
1 Solution
 
James AtkinSenior Principle Software EngineerAuthor Commented:
Maybe there is an ActiveX control which will supply such info ?
0
 
ahoffmannCommented:
nbtstat -a name-of-machine
0
 
alexoCommented:
1) Windows-specific questions should be asked in the windows programming area.
2a) CoCreateGuid()
2b) UuidCreate()


0
Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

 
alexoCommented:
Last bytes of the pointed to value are the MAC address (if there is a NIC, that is...)
0
 
James AtkinSenior Principle Software EngineerAuthor Commented:
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
 
ahoffmannCommented:
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
 
alexoCommented:
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
 
James AtkinSenior Principle Software EngineerAuthor Commented:
That works great !  Thanks !

Is there is an alternative library in Borland C ?
0
 
alexoCommented:
>> Is there is an alternative library in Borland C ?

Huh?
0
 
James AtkinSenior Principle Software EngineerAuthor Commented:
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
 
alexoCommented:
Those libraries implement the functions CoCreateGuid() and UuidCreate().
I don't know what is the Borland counterpart.

0
 
James AtkinSenior Principle Software EngineerAuthor Commented:
Found it !
Borland C contains a library called 'ole2w32.lib'
The function is in there.

Thanks for all the help,

James
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now