delphi WINSOCK 域名获取远程服务器IP


USES WINSOCK;

{$R *.dfm}

function GetIP(const HostName: string): string;
var
  WSAData: TWSAData;
  R: PHostEnt;
  A: TInAddr;
begin
  Result := ''; // '0.0.0.0'
  WSAStartup($101, WSAData);
  R := Winsock.GetHostByName(PAnsiChar(AnsiString(HostName)));
  if Assigned(R) then
  begin
    A := PInAddr(r^.h_Addr_List^)^;
    Result := WinSock.inet_ntoa(A);
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
FORM1.Caption :=GetIP('www.baidu.com');
end;

联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678