uses
  WinSock;

function LocalIP: String;
type
  TaPInAddr = Array[0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe: PHostEnt;
  pptr: PaPInAddr;
  Buffer: Array[0..63] of AnsiChar;
  i: Integer;
  GInitData: TWSAData;
begin
  WSAStartup($101, GInitData);
  Result := '';
  GetHostName(Buffer, SizeOf(Buffer));
  phe := GetHostByName(buffer);
  if phe = nil then Exit;
  pPtr := PaPInAddr(phe^.h_addr_list);
  i := 0;
  while pPtr^[i] <> nil do
  begin
    Result := inet_ntoa(pptr^[i]^);
    Inc(i);
  end;
  WSACleanup;
end;

//测试:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(LocalIP);  //
end;

相关文章:

  • 2021-10-14
  • 2022-02-18
  • 2021-10-21
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-12-24
  • 2022-12-23
  • 2021-10-16
  • 2021-06-12
  • 2021-10-30
相关资源
相似解决方案