|
|
|
IP adresa
|
04.12.2009
|
Úvod
Funkce zjistí a vypíše IP adresu počítače.
Uses
WinSock
Prvky
Button1
Label1
Kód
function ZjistiIP:string;
type TaPInAddr = array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var phe:PHostEnt;
pptr: PaPInAddr;
Buffer: array[0..63] of Char;
I:Integer;
GInitData: TWSADATA;
begin
WSAStartup($101,GInitData);
Result:=''; GetHostName(Buffer,SizeOf(Buffer));
phe:=GetHostByName(buffer);
if phe=nil then Exit;
pptr:=PaPInAddr(Phe^.h_addr_list);
I:=0;while pptr^[I]<> nil do begin
Result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=ZjistiIP;
end;
|
|
|