Delphi obtains the MAC address

Source: Internet
Author: User

Tag: OS Io for Ar CTI code size ad

Function getmacaddress (Index: integer): string;
VaR
NCB: tncb; {NetBIOS control block}
Adapters: tadapterstatus; {Nic status structure}
Lananum: tlanaenum; {NetBIOS Lana}
I: integer;
RC: Char; {code returned by NETBIOS}
STR: string;
Begin
Result: = '';
Try
Zeromemory (@ NCB, sizeof (NCB); {NetBIOS control block erasing}
NCB. ncb_command: = CHR (ncbenum); {Enum}
RC: = NetBIOS (@ NCB); {return code}

NCB. ncb_buffer: = @ lananum; {process The enum command again}
NCB. ncb_length: = sizeof (lananum );
RC: = NetBIOS (@ NCB); {return code}

If ord (RC) <> 0 Then exit;

Zeromemory (@ NCB, sizeof (NCB); {NetBIOS control block erasing}
NCB. ncb_command: = CHR (ncbreset );
NCB. ncb_lana_num: = lananum. Lana [Index];
RC: = NetBIOS (@ NCB );
If ord (RC) <> 0 Then exit;

Zeromemory (@ NCB, sizeof (NCB); {obtain the NIC status}
NCB. ncb_command: = CHR (ncbastat );
NCB. ncb_lana_num: = lananum. Lana [Index];
Strpcopy (NCB. ncb_callname ,'*');
NCB. ncb_buffer: = @ adapters;
NCB. ncb_length: = sizeof (adapters );
RC: = NetBIOS (@ NCB );

STR: = ''; {convert the MAC address to a string}
For I: = 0 to 5 do
STR: = STR + inttohex (INTEGER (adapters. adapter_address [I]), 2 );
Result: = STR;
Finally
End;
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.