http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=266262
uses Winsock;
function GetIP:String;
VAR
ch: Array [1..32] OF Char;
i: Integer;
S: String;
WSData: TWSAData;
MyHost: PHostEnt;
begin
if WSAstartup(2,WSData) <> 0 then Halt(2);
try
if GetHostName(@ch[1],32) <> 0 then Halt(3);
except halt(3);
end;
MyHost := GetHostByName(@ch[1]);
if MyHost = nil then
Halt(4)
else
begin
for i := 0 to 3 do
begin
S := S + Inttostr(Ord(MyHost.H_Addr^));
if i < 3 then
S := S + '.';
end;
end;
Result:=s;
end;