program get_ip;<br>uses<br> winsock,sysutils;<br>VAR<br> ch : ARRAY[1..32] OF Char;<br> i : Integer;<br> WSData: TWSAData;<br> MyHost: PHostEnt;<br>begin<br> IF WSAstartup(2,wsdata)<>0 THEN<br> BEGIN<br> Writeln('can''t start Winsock: Error ',WSAGetLastError);<br> Halt(2);<br> END;<br> try<br> IF getHostName(@ch[1],32)<>0 THEN<br> BEGIN<br> Writeln('getHostName failed');<br> Halt(3);<br> END;<br> except<br> Writeln('getHostName failed');<br> halt(3);<br> end;<br> MyHost:=GetHostByName(@ch[1]);<br> IF MyHost=NIL THEN<br> BEGIN<br> Writeln(GetHostName('+StrPas(@ch[1])+') failed : Error<br>'+IntToStr(WSAGetLastError));<br> Halt(4);<br> END<br> ELSE<br> BEGIN<br> Write('address ');<br> FOR i:=1 TO 4 DO<br> BEGIN<br> Write(Ord(MyHost.h_addr^[i-1]));<br> IF i<4 THEN<br> write('.')<br> ELSE<br> writeln;<br> END;<br> END;<br>end.