Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > Apps

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-11-2012, 07:39 AM
dp_burtol dp_burtol is offline
Junior Member
 
Join Date: May 2010
Posts: 16
Default How to get the MAC Address

How will I get the Mac Address of my PC using Delphi?
Reply With Quote
  #2  
Old 12-11-2012, 10:24 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,318
Default

a quick google was not an option?
http://www.swissdelphicenter.ch/torr...ode.php?id=651
Reply With Quote
  #3  
Old 11-08-2016, 02:47 AM
Rantor777 Rantor777 is offline
Junior Member
 
Join Date: Nov 2016
Location: 127.0.0.1
Posts: 10
Default Method #001

PHP Code:
function GetMACAdressstring
var   
NCBPNCB;   
AdapterPAdapterStatus;   
URetCodePChar;   
RetCodeansichar;   
Iinteger;   
LenumPlanaEnum;   
_SystemIDstring;   
TMPSTRstring
begin   
Result    
:= '';  
 
_SystemID := '';   
Getmem(NCBSizeOf(TNCB));   
Fillchar(NCB^, SizeOf(TNCB), 0);   
Getmem(LenumSizeOf(TLanaEnum));   
Fillchar(Lenum^, SizeOf(TLanaEnum), 0);   
Getmem(AdapterSizeOf(TAdapterStatus));  
 
Fillchar(Adapter^, SizeOf(TAdapterStatus), 0);  
 
Lenum.Length    := chr(0);   
NCB.ncb_command := chr(NCBENUM);   
NCB.ncb_buffer  := Pointer(Lenum);   
NCB.ncb_length  := SizeOf(Lenum);   
RetCode         := Netbios(NCB);   
:= 0;   
repeat     
Fillchar
(NCB^, SizeOf(TNCB), 0);     
Ncb.ncb_command  := chr(NCBRESET);     
Ncb.ncb_lana_num := lenum.lana[i];    
RetCode          := Netbios(Ncb);     
Fillchar(NCB^, SizeOf(TNCB), 0);     
Ncb.ncb_command  := chr(NCBASTAT);     
Ncb.ncb_lana_num := lenum.lana[i];     
// Must be 16     
Ncb.ncb_callname := '*               ';     
Ncb.ncb_buffer := Pointer(Adapter);     
Ncb.ncb_length := SizeOf(TAdapterStatus);     
RetCode        := Netbios(Ncb);   
 
//---- calc _systemId from mac-address[2-5] XOR mac-address[1]...    
 
if (RetCode chr(0)) or (RetCode chr(6)) then     
begin       
_SystemId 
:= IntToHex(Ord(Adapter.adapter_address[0]), 2) + '-' +         IntToHex(Ord(Adapter.adapter_address[1]), 2) + '-' +         IntToHex(Ord(Adapter.adapter_address[2]), 2) + '-' +         IntToHex(Ord(Adapter.adapter_address[3]), 2) + '-' +         IntToHex(Ord(Adapter.adapter_address[4]), 2) + '-' +         IntToHex(Ord(Adapter.adapter_address[5]), 2);    
end;     
Inc(i);   
until (>= Ord(Lenum.Length)) or (_SystemID <> '00-00-00-00-00-00');   FreeMem(NCB);   
FreeMem(Adapter);   
FreeMem(Lenum);   
GetMacAdress := _SystemID
end

Last edited by Rantor777; 11-08-2016 at 02:49 AM.
Reply With Quote
  #4  
Old 11-08-2016, 02:50 AM
Rantor777 Rantor777 is offline
Junior Member
 
Join Date: Nov 2016
Location: 127.0.0.1
Posts: 10
Default Method #002

PHP Code:
Function GetPrimaryNicMacAddressString
Type   
TGUID 
Record     
A
Bword;     
DMSword;     
MAC: Array[ 1..6 Of byte;   
End
Var   
UuidCreateFunc: Function(Var guidTGUID): HResultstdcall;   
handleTHandle;  
 
gTGUID;   
WinVer_OSVersionInfoA;  
iinteger;   
//  ErrCode : HResult; 
Begin   
Try     
WinVer.dwOSVersionInfoSize := sizeof(WinVer); 
// Size     
getversionex(WinVer);  
    
handle := LoadLibrary('RPCRT4.DLL'); 
 
If 
WinVer.dwMajorVersion >= 5 Then {Windows 2000 or later}       
@
UuidCreateFunc := GetProcAddress(Handle'UuidCreateSequential')     
Else 
// (Win98 o menor)       
@UuidCreateFunc := GetProcAddress(Handle'UuidCreate');     
UuidCreateFunc(g); 
 
Result := '';     
For 
:= 1 To 6 Do Result := Result IntToHex(g.MAC], 2); 
   
xcept     
Result 
:= ''

End
End
Reply With Quote
  #5  
Old 11-08-2016, 02:55 AM
Rantor777 Rantor777 is offline
Junior Member
 
Join Date: Nov 2016
Location: 127.0.0.1
Posts: 10
Default Method #003

PHP Code:
interface  

uses .. JwaIpHlpApiJwaIpTypes .. ;  

function 
get_adapters_infoTStrings;  
implementation  ..  
function 
get_adapters_infoTStrings
const   
WIRELESS_ADAPTER 71;   
ETHERNET_ADAPTER 6;  
var   
NumInterfacesCardinal;   
AdapterInfo: array of TIpAdapterInfo;   
OutBufLenULONG;   
iinteger;   
macTipo string;   
AdaptersInfo TStrings
begin   
GetNumberOfInterfaces
(NumInterfaces);   
SetLength(AdapterInfoNumInterfaces);   
OutBufLen := NumInterfaces SizeOf(TIpAdapterInfo);   
GetAdaptersInfo(@AdapterInfo[0], OutBufLen);    
AdaptersInfo := TStringList.Create;    
for 
:= 0 to NumInterfaces do 
begin      
mac 
:= Format('%.2x:%.2x:%.2x:%.2x:%.2x:%.2x',           
[
AdapterInfo[i].Address[0], AdapterInfo[i].Address[1],            
AdapterInfo[i].Address[2], AdapterInfo[i].Address[3],            
AdapterInfo[i].Address[4], AdapterInfo[i].Address[5]]);      
case 
AdapterInfo[i].Type_ of       
WIRELESS_ADAPTER 
Tipo := 'WIF';       
ETHERNET_ADAPTER Tipo := 'ETH';    
 
end;      
if 
AdapterInfo[i].Description <> EmptyStr then       
AdaptersInfo
.Add(IntToStr(i)                
' - ' Tipo                
' - ' AdapterInfo[i].Description                
' - ' mac);   
end;   
Result := AdaptersInfo
end
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:57 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.