给你一个函数用一用
function GetLocalIp:string;
var
aa: pchar;
// bb: in_addr;
hostaddr: phostent;
k,i,j:integer;
bb: wsadata;
begin
GetMem(aa, 80);
FillChar(aa^, 80, 0);
WSAStartup(2,bb);
if gethostname(aa, 80)= SOCKET_ERROR then
Result:='127.0.0.1'
else
begin
hostaddr := gethostbyname(aa);
k:= 0;
for j := 1 to HostAddr^.h_addrtype do
begin
if j > 1 then
Result := Result +' ';
for i := 1 to hostAddr^.h_length do
begin
Result := Result + IntToStr(ord(HostAddr^.H_addr_List^[k]))+'.';
inc(k);
end;
Delete(Result, Length(Result), 1);
end;
end;
FreeMem(aa);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetLocalIp;
end;