给你一个函数。[
]
function getip :string;
VAR
ch : ARRAY[1..32] OF Char;
i : Integer;
WSData: TWSAData;
MyHost: PHostEnt;
ip :string;
begin
ip :='';
IF WSAstartup(2,wsdata)<>0 THEN
BEGIN
application.MessageBox(pchar('不能打开 Winsock: 错误 '+inttostr(WSAGetLastError)),'操作信息',mb_ok+mb_iconinformation);
Halt(2);
END;
try
IF getHostName(@ch[1],32)<>0 THEN
BEGIN
application.MessageBox(pchar('得到IP失败'),'操作信息',mb_ok+mb_iconinformation);
Halt(3);
END;
except
application.MessageBox(pchar('得到IP失败'),'操作信息',mb_ok+mb_iconinformation);
halt(3);
end;
MyHost:=GetHostByName(@ch[1]);
IF MyHost=NIL THEN
BEGIN
Halt(4);
END
ELSE
BEGIN
FOR i:=1 TO 4 DO
BEGIN
ip :=ip+inttostr(ord(myhost.h_addr^[i-1]));
IF i<4 THEN
ip :=ip+'.';
END;
END;
result :=ip;
end;