How to get the IP address of this unit!

zhaozj2021-02-11  230

PROGRAM GET_IP;

Uses

Winsock, sysutils;

VAR

CH: array [1..32] of char;

i: integer;

WSDATA: TWSADATA;

MYHOST: PhoStent;

Begin

IF WSAStartup (2, WSDATA) <> 0 THEN

Begin

Writeln ('Can''t Start Winsock: Error', Wsagetlasterror);

Halt (2);

END;

Try

IF gethostname (@ch [1], 32) <> 0 THEN

Begin

Writeln ('gethostname failed');

Halt (3);

END;

Except

Writeln ('gethostname failed');

Halt (3);

END;

Myhost: = gethostbyname (@CH [1]);

If myhost = nil dam

Begin

Writeln (GethOstname (@CH [1]) ') Failed: Error

' INTOSTR (WsagetLastError);

Halt (4);

End

Else

Begin

Write ('Address');

For i: = 1 to 4 do

Begin

Write (ord (myhost.h_addr ^ [i-1));

IF i <4 THEN

Write ('.')

Else

Writeln;

END;

END;

End.

转载请注明原文地址:https://www.9cbs.com/read-5874.html

New Post(0)