本文整理自网络,侵删。
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);beginFORM1.Caption :=GetIP('www.baidu.com');end;
相关阅读 >>
Delphi tidhttpserver开发http服务端外网无法访问
移植Delphi7的tclientsocket,tserversocket
Delphi 编写activex控件(ocx控件)的知识和样例
更多相关阅读请进入《Delphi》频道 >>