function HostToIP(Name: string; var Ip: string): Boolean; //Delphi XE2 将域名转IP
var
wsdata : TWSAData;
hostName : array [0…255] of Ansichar;
hostEnt : PHostEnt;
addr : PAnsiChar;
begin
WSAStartup ($0101, wsdata);
try
gethostname(hostName,sizeof(hostName));
StrPCopy(hostName, Name);
hostEnt := gethostbyname (hostName);
if Assigned (hostEnt) then
if Assigned (hostEnt^.h_addr_list) then begin
addr := hostEnt.h_addr_list;
if Assigned (addr) then begin
IP := Format (’%d.%d.%d.%d’, [byte (addr [0]),
byte (addr [1]), byte (addr [2]), byte (addr [3])]);
Result := True;
end
else
Result := False;
end
else
Result := False
else begin
Result := False;
end;
finally
WSACleanup;
end;
end;
delphi 域名解析IP 域名转为IP地址
最新推荐文章于 2024-08-27 10:36:01 发布