473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get the MACAddress from the computer


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

--
akayoku
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 17 '05 #1
4 1624
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>

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
"akayoku" wrote:
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


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

Nov 17 '05 #3
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
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++

"Jochen Kalmbach [MVP]" wrote:
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>

--
Greetings
Jochen

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

Nov 17 '05 #4
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
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++

"Jochen Kalmbach [MVP]" wrote:
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>

--
Greetings
Jochen

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

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: tnrABC | last post by:
The approximately 100 books below are for sale. Mostly a selection of mathematics (numerical analysis mostly), computing science (graphics, ai, programming techniques, theory, compilers, operating...
2
by: Toma Marinov | last post by:
Hello ! First, excuse me for my not very good english! >:O( With this code below, I retrieve the MAC address of my network card from WMI class Win32_NetworkAdapter, and add it to ListBox : ...
5
by: z. f. | last post by:
i need to get the computer name from an aspx page. i use System.Windows.Forms.SystemInformation.ComputerName() and it's working fine, but in second thought, it might not be recomended to use the...
0
by: Daylor | last post by:
hi. i have app that im developing in my computer with vs.net 2003 (offcourse). now, this app is running in other computer in the local intranet. in the other computer i dont have vs.net installed...
0
by: py | last post by:
I am trying to execute a batch script on a remote computer. The batch script looks like: @echo off start c:\python24\python.exe c:\a_script.py Here's the setup: Computer A (my computer),...
1
by: DaTurk | last post by:
Hi, I want to to find the Mac address of the NIC being used by a given process using a corresponding IP address. It should be pointed out that the machines that this program will be running on...
0
by: Paul Brady | last post by:
I volunteer at a youth ministry agency and help them with their student database. They have two computers, both running Windows XP. Both have Office 2002 installed without Access, except that...
0
by: masalamod | last post by:
http://www.cextube.com/search.php? search=computer++languages&submit=Video+Search http://www.cextube.com/search.php? search=computer++languages&submit=Video+Search ...
0
by: Winder | last post by:
Computer Data Recovery Help 24/7 Data recovering tools and services is our focus. We will recover your data in a cost effective and efficient manner. We recover all operating systems and media....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.