Q&A

  • 인터넷 접속시에만 Mac Address 가 구해지네요..
한델 팁에서 Mac Address 구하는 함수를
찾아 약간 수정후 사용하고 있습니다.(아래 참조)
근데 인터넷 연결시에만 구해지고 미접속시엔
'파이프가 닫히고 있는 중입니다' 라고 뜨네요.
항상 구해지도록 하고 싶은데
인연 닿는 고수님께 한수 부탁드립니다.

  
unit Lock;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
  Buttons,Registry;

const
MAX_ADAPTER_ADDRESS_LENGTH = 8;
MAX_ADAPTER_NAME_LENGTH = 256;
MAX_ADAPTER_DESCRIPTION_LENGTH = 128;

type
TMacAddress = array[1..MAX_ADAPTER_ADDRESS_LENGTH] of byte;

type
PTIP_ADDRESS_STRING = ^TIP_ADDRESS_STRING;
TIP_ADDRESS_STRING = array[0..15] of char;

type
PTIP_ADDR_STRING = ^TIP_ADDR_STRING;
TIP_ADDR_STRING = packed record
   Next: PTIP_ADDR_STRING;
   IpAddress: TIP_ADDRESS_STRING;
   IpMask: TIP_ADDRESS_STRING;
   Context: DWORD;
end;

type
TTIME_T = array[1..325] of byte;

PTIP_ADAPTER_INFO = ^TIP_ADAPTER_INFO;
TIP_ADAPTER_INFO = packed record
   Next: PTIP_ADAPTER_INFO;
   ComboIndex: DWORD;
   AdapterName: array[1..MAX_ADAPTER_NAME_LENGTH + 4] of char;
   Description: array[1..MAX_ADAPTER_DESCRIPTION_LENGTH + 4] of char;
   AddressLength: UINT;
   Address: array[1..MAX_ADAPTER_ADDRESS_LENGTH] of byte;
   Index: DWORD;
   aType: UINT;
   DHCPEnabled: UINT;
   CurrentIPAddress: PTIP_ADDR_STRING;
   IPAddressList: TIP_ADDR_STRING;
   GatewayList: TIP_ADDR_STRING;
   DHCPServer: TIP_ADDR_STRING;
   HaveWINS: BOOL;
   PrimaryWINSServer: TIP_ADDR_STRING;
   SecondaryWINSServer: TIP_ADDR_STRING;
   LeaseObtained: TTIME_T;
   LeaseExpires: TTIME_T;
end;

function MacAddr2Str( MacAddr: TMacAddress; size: integer ): string;
function Get_AdaptersInfo : string;

implementation

function GetAdaptersInfo( pAdapterInfo: PTIP_ADAPTER_INFO; pOutBufLen: PULONG ): DWORD;
stdcall; external 'IPHLPAPI.DLL';

function MacAddr2Str( MacAddr: TMacAddress; size: integer ): string;
var
i : integer;
begin
if Size = 0 then
begin
   Result := '000000000000';//'00-00-00-00-00-00';
   EXIT;
end
else Result := '';
//
for i := 1 to Size do
   Result := Result + IntToHex( MacAddr[i], 2 );// + '-';
//Delete( Result, Length( Result ), 1 );
end;

function Get_AdaptersInfo : string;
var
Error, BufLen : DWORD;
AdapterInfo : PTIP_ADAPTER_INFO;
Descr : string;
begin
BufLen := SizeOf( AdapterInfo^ );
New(AdapterInfo);

Error := GetAdaptersInfo(AdapterInfo, @BufLen );
Result := '';
if Error = NO_ERROR then
begin
   while ( AdapterInfo <> nil ) do
   begin
     with AdapterInfo^ do
     begin
       Result := Result + MacAddr2Str( TMacAddress(        Address ),AddressLength);
       AdapterInfo := Next;
     end;
   end;
end
else begin
  Application.MessageBox('렌카드가 필요합니다','준비후 다시 실행하세요',0);
  Exit;
end;

Dispose( AdapterInfo );
end;
0  COMMENTS