半
半天云
Unregistered / Unconfirmed
GUEST, unregistred user!
测试IP地址是否存在
//uses winsock
function testip(IP:string):string;
var
WSAData:TWSADATA;
AddrWORD;
begin
WSAStartup(2, WSAData);
Addr:=inet_addr(PChar(IP));
if gethostbyaddr(@Addr,sizeof(Addr),PF_INET)=nil then
result:=''
else result:=ip;
WSACleanup();
end;
通过机器名得到IP地址
function procedure TForm1.nametoip(name:string):string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
result:='';
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(name));
if HostEnt <> nil then
begin
with HostEnt^ do
result:= Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
end;
WSACleanup;
end;
□把域名转化为IP地址
uses winsock;
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
pHHostent;
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;
//uses winsock
function testip(IP:string):string;
var
WSAData:TWSADATA;
AddrWORD;
begin
WSAStartup(2, WSAData);
Addr:=inet_addr(PChar(IP));
if gethostbyaddr(@Addr,sizeof(Addr),PF_INET)=nil then
result:=''
else result:=ip;
WSACleanup();
end;
通过机器名得到IP地址
function procedure TForm1.nametoip(name:string):string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
result:='';
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(name));
if HostEnt <> nil then
begin
with HostEnt^ do
result:= Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
end;
WSACleanup;
end;
□把域名转化为IP地址
uses winsock;
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
pHHostent;
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;