Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Get the MACAddress from the computer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
akayoku - 23 Jun 2005 07:19 GMT
Hello all,

I'm working on a school project to make a security program. I need to
get the MAC Address from the computer. That is the "Physical Address"
when you type "ipconfig/all" in MSDOS command prompt.

It is urgent and I have spent pretty much time there, but still don't
know what to do. I am an amateur in programming. I'd greatly appreciate
your opinion. Thanks.

~~~ Landy


Jochen Kalmbach [MVP] - 23 Jun 2005 07:26 GMT
Hi akayoku!
> I'm working on a school project to make a security program. I need to
> get the MAC Address from the computer. That is the "Physical Address"
> when you type "ipconfig/all" in MSDOS command prompt.

See: How To Get the MAC Address for an Ethernet Adapter
http://support.microsoft.com/kb/118623/en-us

Or try this one:

<code>
CString GetMACAddress(int adapternumber)
{
 int nAdapterCount = 0;
 ULONG ip;
 ULONG buflen;
 PIP_ADAPTER_INFO pAdInfo = NULL;
 PIP_ADAPTER_INFO pAdInfo_c = NULL;

 buflen = 0;
 GetAdaptersInfo(pAdInfo, &buflen); //since buflen=0, buffer is
    // too small. function returns required buffersize in buflen.
 pAdInfo = (struct _IP_ADAPTER_INFO *)new UCHAR[buflen+1];
 pAdInfo_c = pAdInfo;
 if (GetAdaptersInfo(pAdInfo, &buflen) == ERROR_SUCCESS)
 {
  do
  {
   ip = inet_addr(pAdInfo->IpAddressLi­st.IpAddress.String);
   if ((ip != 0)&&(ip != 0x7f000001))
   {
    nAdapterCount++;
    if ((nAdapterCount == adapternumber)||(adapternumber == 0))
    {
     if (pAdInfo->AddressLength != 0)
     {
      CString macstr;
      for (int i = 0; i < (int)pAdInfo->AddressLength; i++)
      {
       CString temp;
       temp.Format(_T(" %02X"), pAdInfo->Address[i]);
       macstr += temp;
      }
      delete pAdInfo;
      return macstr;
     }
    }
   }
  } while ((pAdInfo->Next != NULL)&&((pAdInfo = pAdInfo->Next) !=
pAdInfo));
 }
 delete pAdInfo_c;
 return _T("");
}
</code>

Signature

Greetings
  Jochen

   My blog about Win32 and .NET
   http://blog.kalmbachnet.de/

German - 06 Jul 2005 17:26 GMT
I have tried with the code, but I have received the next mesage :

error C2065: 'PIP_ADAPTER_INFO' : undeclared identifier

After that, I added #include Iphlpapi.h with no result !!
Do you have any other suggestion ??
Thanks in advanced,

German
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

> Hi akayoku!
> > I'm working on a school project to make a security program. I need to
[quoted text clipped - 51 lines]
> }
> </code>
Pavel A. - 23 Jun 2005 12:27 GMT
> Hello all,
>
[quoted text clipped - 5 lines]
> know what to do. I am an amateur in programming. I'd greatly appreciate
> your opinion. Thanks.

> ~~~ Landy

Hi,
since this is a school project and you don't have much time,
IMHO you can quite well spawn ipconfig and parse it's output.
Also, instead of ipconfig, you can use :
netsh interface ip show config

So, the task is reduced to using system(...) and trivial scanning of text
file.

/* A real "commercial strength" solution won't use anything dependent on
TCPIP, because IP protocol driver may be just not bound to your ethernet card
:)
Also it won't be fooled by "overriding" the built-in MAC address :))
Probably it will use WMI or low-level NDIS ioctls. */

Good luck,
--PA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.