I
ilmm520
Unregistered / Unconfirmed
GUEST, unregistred user!
uses winsock;
function HostToIP(Name: string; var Ip: string): Boolean;
var
wsdata : TWSAData;
hostName : array [0..255] of char;
hostEnt : PHostEnt;
addr : PChar;
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;
procedure TForm1.Button1Click(Sender: TObject);
var
IP: string;
DNS: string;
begin
if Edit1.Text<>'' then
try
begin
DNS := Edit1.Text;
HostToIp(DNS, IP);
Edit2.Text:=IP;
end;
except
ShowMessage('出错!');
end;
end.
这个功能可以域名转ip
但是,问题出来了,如果申请的域名马上改一下ip哪么用这个的时候,得到的ip还是原来的ip
如何让sock先关一下.再连接.
function HostToIP(Name: string; var Ip: string): Boolean;
var
wsdata : TWSAData;
hostName : array [0..255] of char;
hostEnt : PHostEnt;
addr : PChar;
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;
procedure TForm1.Button1Click(Sender: TObject);
var
IP: string;
DNS: string;
begin
if Edit1.Text<>'' then
try
begin
DNS := Edit1.Text;
HostToIp(DNS, IP);
Edit2.Text:=IP;
end;
except
ShowMessage('出错!');
end;
end.
这个功能可以域名转ip
但是,问题出来了,如果申请的域名马上改一下ip哪么用这个的时候,得到的ip还是原来的ip
如何让sock先关一下.再连接.