DelphiFAQ Home Search:

How to determine your MAC address in Windows 2000/ WinXP

 

comments6 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

Question:

How can I obtain the network adapter serial number or ID? (MAC = Media Access Control)

Answer:

In Windows 2000 and Windows XP you can use the command line tool ipconfig.

Start a shell by opening the run box and entering cmd and hit enter. A new terminal window should be created. There issue the command ipconfig /all.

One of the output lines will say: Physical Address.
Next to it you will see your network card's MAC address.


Content-type: text/html

Comments:

2006-03-14, 09:20:23
anonymous from United States  
rating
2006-06-18, 08:41:37
anonymous from Romania  
Function TNetworkCards.GetMacAddress (Address: String; var MacAddr: String): Boolean;
var
dwRemoteIP: DWORD;
PhyAddrLen: Longword;
pMacAddr : array [0..1] of Longword;
temp: array [0..5] of byte;
I: Byte;
begin
Result := false;
dwremoteIP := inet_addr (PChar(address));
if dwremoteIP <> 0 then
begin
PhyAddrLen := 6;
if SendARP (dwremoteIP, 0, @pMacAddr, @PhyAddrLen) = NO_ERROR then
begin
if (PhyAddrLen <> 0) and (pMacAddr[0] <> 0) then
begin
Move (pMacAddr, temp, 6);
address := '';
For I := 0 to 5 do
address := address + inttohex (temp[i], 2)+'-';
Delete (address, Length (address), 1);
Result := true;
end;
end;
end;
MacAddr:= Address;
end;
2006-07-12, 07:36:31
anonymous from Netherlands  
unit ethernet_address;

interface

uses classes, sysutils;

const
MAX_INTERFACE_NAME_LEN = $100;
ERROR_SUCCESS = 0;
MAXLEN_IFDESCR = $100;
MAXLEN_PHYSADDR = 8;

MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0 ;
MIB_IF_OPER_STATUS_UNREACHABLE = 1;
MIB_IF_OPER_STATUS_DISCONNECTED = 2;
MIB_IF_OPER_STATUS_CONNECTING = 3;
MIB_IF_OPER_STATUS_CONNECTED = 4;
MIB_IF_OPER_STATUS_OPERATIONAL = 5;

MIB_IF_TYPE_OTHER = 1;
MIB_IF_TYPE_ETHERNET = 6;
MIB_IF_TYPE_TOKENRING = 9;
MIB_IF_TYPE_FDDI = 15;
MIB_IF_TYPE_PPP = 23;
MIB_IF_TYPE_LOOPBACK = 24;
MIB_IF_TYPE_SLIP = 28;

MIB_IF_ADMIN_STATUS_UP = 1;
MIB_IF_ADMIN_STATUS_DOWN = 2;
MIB_IF_ADMIN_STATUS_TESTING = 3;


type

MIB_IFROW = Record
wszName : Array[0 .. (MAX_INTERFACE_NAME_LEN*2-1)] of char;
dwIndex : LongInt;
dwType : LongInt;
dwMtu : LongInt;
dwSpeed : LongInt;
dwPhysAddrLen : LongInt;
bPhysAddr : Array[0 .. (MAXLEN_PHYSADDR-1)] of Byte;
dwAdminStatus : LongInt;
dwOperStatus : LongInt;
dwLastChange : LongInt;
dwInOctets : LongInt;
dwInUcastPkts : LongInt;
dwInNUcastPkts : LongInt;
dwInDiscards : LongInt;
dwInErrors : LongInt;
dwInUnknownProtos : LongInt;
dwOutOctets : LongInt;
dwOutUcastPkts : LongInt;
dwOutNUcastPkts : LongInt;
dwOutDiscards : LongInt;
dwOutErrors : LongInt;
dwOutQLen : LongInt;
dwDescrLen : LongInt;
bDescr : Array[0 .. (MAXLEN_IFDESCR - 1)] of Char;
end;

function Get_EthernetAddresses: TStringList;

Function GetIfTable( pIfTable : Pointer;
VAR pdwSize : LongInt;
bOrder : LongInt ): LongInt; stdcall;


implementation

Function GetIfTable; stdcall; external 'IPHLPAPI.DLL';

function Get_EthernetAddresses: TStringList;
const
_MAX_ROWS_ = 20;

type
_IfTable = Record
nRows : LongInt;
ifRow : Array[1.._MAX_ROWS_] of MIB_IFROW;
end;

VAR
pIfTable : ^_IfTable;
TableSize : LongInt;
tmp : String;
i,j : Integer;
ErrCode : LongInt;
begin
pIfTable := nil; / ------------------------------------------------------------------
Result:=TStringList.Create;
if Assigned(Result) then
try
//-------------------------------------------------------
// First: just get the buffer size.
// TableSize returns the size needed.
TableSize:=0; // Set to zero so the GetIfTabel function
// won't try to fill the buffer yet,
// but only return the actual size it needs.
GetIfTable(pIfTable, TableSize, 1);
if (TableSize < SizeOf(MIB_IFROW)+Sizeof(LongInt)) then
begin
Exit; // less than 1 table entry?!
end; // if-end.

// Second:
// allocate memory for the buffer and retrieve the
// entire table.
GetMem(pIfTable, TableSize);
ErrCode := GetIfTable(pIfTable, TableSize, 1);
if ErrCode<>ERROR_SUCCESS then
begin
Exit; // OK, that did not work.
// Not enough memory i guess.
end; // if-end.

// Read the ETHERNET addresses.
for i := 1 to pIfTable^.nRows do
try
if pIfTable^.ifRow[i].dwType=MIB_IF_TYPE_ETHERNET then
begin
tmp:='';
for j:=0 to pIfTable^.ifRow[i].dwPhysAddrLen-1 do
begin
tmp := tmp + format('%.2x',
[ pIfTable^.ifRow[i].bPhysAddr[j] ] );
end; // for-end.
//-------------------------------------
if Length(tmp)>0 then Result.Add(tmp);
end; // if-end.
except
Exit;
end; // if-try-except-end.
finally
if Assigned(pIfTable) then FreeMem(pIfTable,TableSize);
end; // if-try-finally-end.
end;

end.
// Enjoy!

2007-01-07, 04:06:51
sma_aouissi@yahoo.fr  
rating
Hi
In windows 2000 series you can use the 'ipconfig' command to show ip or address MAC
For shwo all use 'ipconfig /all'

For confirmed uer use 'netsh' command with diag option
2008-06-14, 14:31:26
SomeBody  
dose not work in vista
2009-12-05, 08:32:27
anonymous  
getmac

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: