以下是从DELPHI一个站点的得到的答案
看是否合适
Detect my own IP Address ?
From: Andreas Hoerstemeier <andy@scp.de>
> How can I detect my own IP address in delphi 1?
---------------------------------------------------------------------
function my_ip_address:longint;
const
bufsize=255;
var
buf: pointer;
RemoteHost : PHostEnt; (* No, don't free it! *)
begin
buf:=NIL;
try
getmem(buf,bufsize);
winsock.gethostname(buf,bufsize); (* this one maybe without domain *)
RemoteHost:=Winsock.GetHostByName(buf);
if RemoteHost=NIL then
my_ip_address:=winsock.htonl($07000001) (* 127.0.0.1 *)
else
my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
finally
if buf<>NIL then freemem(buf,bufsize);
end;
result:=winsock.ntohl(result);
end;
----------------------------------------------------------------------
This give the (first) network address of the local computer, and if not connected the 127.0.0.1 as the standard address for the local computer.
You only need a winsock.dcu/winsock.pas as this one isn't included with D1; I have one together with my tcpip component pack (where I snipped out the above routine).