to pipi:
unit Unit2;
interface
uses
Classes,winsock,sysutils,windows;
type
convert = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
uses unit1;
function GetIP(Name:string) : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe
HostEnt;
pptr : PaPInAddr;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
phe :=GetHostByName(pchar(Name));
pptr := PaPInAddr(Phe^.h_addr_list);
result:=StrPas(inet_ntoa(pptr^[0]^));
WSACleanup;
end;
function GetDomainName(Ip:string):string;
var
pH
Hostent;
data:twsadata;
ii:dword;
begin
WSAStartup($101, Data);
ii:=inet_addr(pchar(ip));
pH:=gethostbyaddr(@ii,sizeof(ii),PF_INET);
if (ph<>nil) then
result:=pH.h_name
else
result:='';
WSACleanup();
end;
procedure convert.Execute;
var i:integer;temp:string;comp:boolean;
begin
temp:=form1.Edit1.Text;
comp:=false;
for i:=1 to length(temp) do begin
if ((temp
>'9') or (temp<'0')) and (temp<>'.') then begin//看是否是IP
form1.Button1.Caption:='终止';
Form1.Edit1.Text:=GetIp(temp);
comp:=true;
Form1.Button1.Caption:='转化';
end;
if comp then break;
end;
if not comp then begin
form1.Button1.Caption:='终止';
Form1.Edit1.Text:=GetDomainName(temp);
Form1.Button1.Caption:='转化';
end;
end;
end.
to g622:
请说的详细一点。
多谢各位。