本文整理自网络,侵删。
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 system.sysutils.tmarshaller 与 system.tmarshal
Delphi 文件查找findfirst,findnext,findclose
Delphi getmimetypefromfile 获取文件mime类型
更多相关阅读请进入《Delphi》频道 >>