uses WinInet
const
MAX_PACKET_SIZE = $10000;
SIO_RCVALL = $98000001;
WSA_VER = $202;
MAX_ADAPTER_NAME_LENGTH = 256;
MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
MAX_ADAPTER_ADDRESS_LENGTH = 8;
IPHelper = 'iphlpapi.dll';
ICMP_ECHO = 8;
ICMP_ECHOREPLY = 0;
// LAN
MODEM = 1;
LAN = 2;
PROXY = 4;
BUSY = 8;
type
USHORT = WORD;
ULONG = DWORD;
time_t = Longint;
TIPHeader = packed record
iph_verlen: UCHAR;
iph_tos: UCHAR;
iph_length: USHORT;
iph_id: USHORT;
iph_offset: USHORT;
iph_ttl: UCHAR;
iph_protocol: UCHAR;
iph_xsum: USHORT;
iph_src: ULONG;
iph_dest: ULONG;
end;
PIPHeader = ^TIPHeader;
TTCPHeader = packed record
sourcePort: USHORT;
destinationPort: USHORT;
sequenceNumber: ULONG;
acknowledgeNumber: ULONG;
dataoffset: UCHAR;
flags: UCHAR;
windows: USHORT;
checksum: USHORT;
urgentPointer: USHORT;
end;
PTCPHeader = ^TTCPHeader;
TUDPHeader = packed record
sourcePort: USHORT;
destinationPort: USHORT;
len: USHORT;
checksum: USHORT;
end;
PUDPHeader = ^TUDPHeader;
TICMPHeader = packed record
IcmpType : BYTE;
IcmpCode : BYTE;
IcmpChecksum : WORD;
IcmpId : WORD;
IcmpSeq : WORD;
IcmpTimestamp : DWORD;
end;
PICMPHeader = ^TICMPHeader;
IP_ADDRESS_STRING = record
S: array [0..15] of Char;
end;
IP_MASK_STRING = IP_ADDRESS_STRING;
PIP_MASK_STRING = ^IP_MASK_STRING;
PIP_ADDR_STRING = ^IP_ADDR_STRING;
IP_ADDR_STRING = record
Next: PIP_ADDR_STRING;
IpAddress: IP_ADDRESS_STRING;
IpMask: IP_MASK_STRING;
Context: DWORD;
end;
PIP_ADAPTER_INFO = ^IP_ADAPTER_INFO;
IP_ADAPTER_INFO = record
Next: PIP_ADAPTER_INFO;
ComboIndex: DWORD;
AdapterName: array [0..MAX_ADAPTER_NAME_LENGTH + 3] of Char;
Description: array [0..MAX_ADAPTER_DESCRIPTION_LENGTH + 3] of Char;
AddressLength: UINT;
Address: array [0..MAX_ADAPTER_ADDRESS_LENGTH - 1] of BYTE;
Index: DWORD;
Type_: UINT;
DhcpEnabled: UINT;
CurrentIpAddress: PIP_ADDR_STRING;
IpAddressList: IP_ADDR_STRING;
GatewayList: IP_ADDR_STRING;
DhcpServer: IP_ADDR_STRING;
HaveWins: BOOL;
PrimaryWinsServer: IP_ADDR_STRING;
SecondaryWinsServer: IP_ADDR_STRING;
LeaseObtained: time_t;
LeaseExpires: time_t;
end;
//
private
{ Private-Deklarationen }
procedure ReadLanInterfaces;
//
function GetAdaptersInfo(pAdapterInfo: PIP_ADAPTER_INFO;
var pOutBufLen: ULONG): DWORD; stdcall; external IPHelper;
//
procedure TForm1.ReadLanInterfaces;
var
InterfaceInfo,
TmpPointer: PIP_ADAPTER_INFO;
IP: PIP_ADDR_STRING;
Len: ULONG;
begin
if GetAdaptersInfo(nil, Len) = ERROR_BUFFER_OVERFLOW then
begin
GetMem(InterfaceInfo, Len);
try
if GetAdaptersInfo(InterfaceInfo, Len) = ERROR_SUCCESS then
begin
TmpPointer := InterfaceInfo;
repeat
IP := @TmpPointer.IpAddressList;
repeat
ComboBox1.Items.Add(Format('%s - [%s]',
[IP^.IpAddress.S, TmpPointer.Description]));
IP := IP.Next;
until IP = nil;
TmpPointer := TmpPointer.Next;
until TmpPointer = nil;
end;
finally
FreeMem(InterfaceInfo);
end;
end;
if ComboBox1.Items.Count = 0 then
begin
Exit;
end
else
ComboBox1.ItemIndex := 0;
end;
Beispiel :
procedure TForm1.FormCreate(Sender: TObject);
begin
ReadLanInterfaces;
end;
Keine Kommentare:
Kommentar veröffentlichen