can anybody tell me, how do get the MAC - adress of the network-adapter
(in Delphi or C++) or any other local uniqua number of the computer ?
Thanks
HTH
Andreas Junker <andreas...@t-online.de> wrote in message
news:3847998A...@t-online.de...
> can anybody tell me, how do get the MAC - adress of the network-adapter
> (in Delphi or C++) or any other local uniqua number of the computer ?
Hello Andreas, try the following code:
Uses
NB30, SysUtils;
Type
TMACAddress = Array[0..5] Of Byte;
PMACAddress = ^TMACAddress;
Function ResetLANAdapter(AdapterNumber: Byte): Byte;
Var
tmpNCB: PNCB;
Begin
New(tmpNCB);
ZeroMemory(tmpNCB, SizeOf(TNCB));
Try
With tmpNCB^ Do
Begin
ncb_lana_num := Char(AdapterNumber); // Set AdapterNumber
ncb_command := Char(NCBRESET); // Set command RESET
NetBios(tmpNCB);
Result := Byte(ncb_cmd_cplt);
End;
Finally
Dispose(tmpNCB);
End;
End;
Function GetMACAddress(AdapterNumber: Byte; MACAddress: PMACAddress): Byte;
Var
tmpNCB: PNCB;
AdapterStatus: PAdapterStatus;
begin
New(tmpNCB);
ZeroMemory(tmpNCB, SizeOf(TNCB));
tmpNCB.ncb_length := SizeOf(TAdapterStatus) + 255 * SizeOf(TNameBuffer);
GetMem(AdapterStatus, tmpNCB.ncb_length);
Try
With tmpNCB^ Do
Begin
ZeroMemory(MACAddress, SizeOf(TMACAddress));
ncb_buffer := PChar(AdapterStatus);
ncb_callname := '* ' + #0;
ncb_lana_num := Char(AdapterNumber);
ncb_command := Char(NCBASTAT);
NetBios(tmpNCB);
Result := Byte(ncb_cmd_cplt);
If Result = NRC_GOODRET Then
MoveMemory(MACAddress, AdapterStatus, SizeOf(TMACAddress));
End;
Finally
FreeMem(AdapterStatus);
Dispose(tmpNCB);
End;
End;
Function GetMACAddressAsString(AdapterNumber: Byte): String;
Var
tmpMACAddress: TMACAddress;
Begin
If Win32Platform = VER_PLATFORM_WIN32_NT Then
If ResetLANAdapter(AdapterNumber) <> NRC_GOODRET Then
Begin
Result := '??-??-??-??-??-??';
Exit;
End;
If GetMACAddress(AdapterNumber, @tmpMACAddress) = NRC_GOODRET Then
Result := Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
[tmpMACAddress[0], tmpMACAddress[1], tmpMACAddress[2], tmpMACAddress[3],
tmpMACAddress[4], tmpMACAddress[5]])
Else
Result := '??-??-??-??-??-??';
End;
Frank,
Nice to see you here again!
You offer a great example on get MAC address, there is a probelm on
the above code: some net cards' driver offer a function to change MAC
address.
My net card is "D-Link DE-220". You can buy it under US$20. All D-Link
card (not only D-Link) can easily change MAC address by following
steps:
1. Start control panel.
2. Double click the "NetWork" icon.
3. Select the Adapter tab.
4. Double click the adapter in the list.
5. Change any MAC address you want.
6. Confirm any further promt and restart the computer.
7. Try GetMACAddressAsString again, you will get new MAC address.
(you can also try Win/NT's (maybe Win/98 has this also) command
"ipconfig /all")
Some softwares are not cheated by the above setting. I don't know how
they do it, is anyone know?
Philip Ma
> You offer a great example on get MAC address, there is a probelm on
> the above code: some net cards' driver offer a function to change MAC
> address.
Hi Philip,
maybe it愀 possible to change MAC-address of some network-cards, but the only
thing, Andreas wanted to know is how to get it.
IMO MAC-address is no relyable way to protect software from being copied
illegal, because the user could change his card, perhaps it愀 damaged or
whatever else. You can愒 expect of a user to call for a new registration key,
everytime he is replacing some components of his machine.
YMMV, but after careful consideration, I think you will change your mind.
Frank
P.S.: Sorry Phillip, still no idea for your problem
news://forums.inprise.com/383f25c8.20060936%40forums.inprise.com
You bind an Ipx socket to it.
--
Paul Loht
-Real men do it with blocking sockets.
Paul,
Could you show me how to do it with a simple example/description?
Thanks!
Philip Ma
Pete Coe
http://www.delphipantheon.com