Take MAC address (including multiple network cards), the best way to support vista,win7

Source: Internet
Author: User

Take MAC address (including multiple network cards), the best way to support vista,win7

Unit Unit1;

Interface

Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
WinSock, Stdctrls;

Const
Max_hostname_len = 128; {from iptypes. H
Max_domain_name_len = 128;
Max_scope_id_len = 256;
Max_adapter_name_length = 256;
Max_adapter_description_length = 128;
Max_adapter_address_length = 8;

Type
tipaddressstring = array[0..4*4-1] of Char;

pipaddrstring = ^tipaddrstring;
tipaddrstring = Record
next:pipaddrstring;
ipaddress:tipaddressstring;
ipmask:tipaddressstring;
Context:integer;
End;

Pfixedinfo = ^tfixedinfo;
Tfixedinfo = Record {Fixed_info}
HOSTNAME:ARRAY[0..MAX_HOSTNAME_LEN+3] of Char;
DOMAINNAME:ARRAY[0..MAX_DOMAIN_NAME_LEN+3] of Char;
currentdnsserver:pipaddrstring;
dnsserverlist:tipaddrstring;
Nodetype:integer;
SCOPEID:ARRAY[0..MAX_SCOPE_ID_LEN+3] of Char;
Enablerouting:integer;
Enableproxy:integer;
Enabledns:integer;
End;

Pipadapterinfo = ^tipadapterinfo;
Tipadapterinfo = Record {Ip_adapter_info}
Next:pipadapterinfo;
Comboindex:integer;
ADAPTERNAME:ARRAY[0..MAX_ADAPTER_NAME_LENGTH+3] of Char;
DESCRIPTION:ARRAY[0..MAX_ADAPTER_DESCRIPTION_LENGTH+3] of Char;
Addresslength:integer;
Address:array[1..max_adapter_address_length] of Byte;
Index:integer;
_type:integer;
Dhcpenabled:integer;
currentipaddress:pipaddrstring;
ipaddresslist:tipaddrstring;
gatewaylist:tipaddrstring;
dhcpserver:tipaddrstring;
Havewins:bool;
primarywinsserver:tipaddrstring;
secondarywinsserver:tipaddrstring;
Leaseobtained:integer;
Leaseexpires:integer;
End;

Type
TForm1 = Class (Tform)
Button1:tbutton;
Memo1:tmemo;
Procedure Button1Click (Sender:tobject);
Private
{Private declarations}
Procedure Getadapterinformation;
Public
{Public declarations}
End

Var
Form1:tform1;

Function Sendarp (Ipaddr:ulong;
Temp:dword;
Ulmacaddr:pointer;
Ulmacaddrleng:pointer): DWord; stdcall;

Implementation

{$R *.DFM}

Function Sendarp; External ' Iphlpapi.dll ' Name ' sendarp ';
Function GetAdaptersInfo (ai:pipadapterinfo; Var Buflen:integer): Integer;
stdcall; External ' Iphlpapi.dll ' Name ' getadaptersinfo ';

Procedure Tform1.getadapterinformation;
Var
Ai,work:pipadapterinfo;
Size:integer;
Res:integer;
I:integer;

Function Mactostr (bytearr:pbyte; Len:integer): String;
Begin
Result: = ';
while (Len > 0) do Begin
Result: = Result+inttohex (bytearr^,2) + '-';
Bytearr: = Pointer (Integer (Bytearr) +sizeof (Byte));
Dec (Len);
End;
SetLength (Result,length (Result)-1); {Remove Last Dash}
End;

Function getaddrstring (addr:pipaddrstring): String;
Begin
Result: = ';
while (Addr <> nil) do Begin
Result: = result+ ' A: ' +addr^. ipaddress+ ' M: ' +addr^. ipmask+ #13;
ADDR: = addr^. Next;
End;
End;

Function timettodatetimestr (Timet:integer): String;
Const Unixdatedelta = 25569; {days between 12/31/1899 and 1/1/1970}
Var
Dt:tdatetime;
Tz:ttimezoneinformation;
Res:dword;

Begin
If (TimeT = 0) then Result: = '
Else Begin
{Unix time_t is secs since 1/1/1970}
DT: = unixdatedelta+ (TimeT/(24*60*60)); {in UTC}
{Calculate bias}
Res: = GetTimeZoneInformation (TZ);
If (Res = time_zone_id_invalid) then Raiselastwin32error;
If (Res = time_zone_id_standard) then Begin
DT: = dt-((TZ). Bias+tz. StandardBias)/(24*60));
Result: = Datetimetostr (DT) + ' +widechartostring (TZ. StandardName);
End
Else Begin {Daylight Saving time}
DT: = dt-((TZ). Bias+tz. DaylightBias)/(24*60));
Result: = Datetimetostr (DT) + ' +widechartostring (TZ. DaylightName);
End;
End;
End;

Begin
Memo1.Lines.Clear;
Size: = 5120;
Getmem (ai,size);
Res: = GetAdaptersInfo (ai,size);
If (Res <> error_success) then Begin
SetLastError (Res);
Raiselastwin32error;
End;
With Memo1,lines do Begin
Work: = AI;
I: = 1;
Repeat
ADD (");
ADD (' Adapter ' + inttostr (I));
Add (' Comboindex: ' +inttostr (work^. Comboindex));
ADD (' Adapter name: ' +work^. AdapterName);
Add (' Description: ' +work^. Description);
ADD (' Adapter address: ' +mactostr (@Work ^. address,work^. Addresslength));
Add (' Index: ' +inttostr (work^. Index));
Add (' Type: ' +inttostr (Work^._type));
Add (' DHCP: ' +inttostr (work^. dhcpenabled));
Add (' Current IP: ' +getaddrstring (work^. currentipaddress));
ADD (' IP addresses: ' +getaddrstring (@Work ^. Ipaddresslist));
ADD (' Gateways: ' +getaddrstring (@Work ^. Gatewaylist));
ADD (' DHCP servers: ' +getaddrstring (@Work ^. DHCPServer));
Add (' has WINS: ' +inttostr (Integer (work^. (havewins)));
Add (' Primary WINS: ' +getaddrstring (@Work ^. Primarywinsserver));
ADD (' Secondary WINS: ' +getaddrstring (@Work ^. Secondarywinsserver));
ADD (' Lease obtained: ' +timettodatetimestr (work^. leaseobtained));
ADD (' Lease Expires: ' +timettodatetimestr (work^. Leaseexpires));
INC (I);
Work: = work^. Next;
Until (work = nil);
End;
Freemem (AI);
End

Procedure Tform1.button1click (Sender:tobject);
Begin
Getadapterinformation;
End

End.

Take MAC address (including multiple network cards), the best way to support vista,win7

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.