function iptoname(ip:string):string;
var
WSAData:TWSAData;
p:PHostEnt;
InetAddr:dword;
begin
WSAStartup(2, WSAData);
InetAddr:= inet_addr(PChar(IP));
try
p:=GetHostByAddr(@InetAddr, Length(IP), PF_Inet);
result:=p^.h_name;
except
result:='';
end;
end;function 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是192.168.0.1
var
WSAData:TWSAData;
p:PHostEnt;
InetAddr:dword;
begin
WSAStartup(2, WSAData);
InetAddr:= inet_addr(PChar(IP));
try
p:=GetHostByAddr(@InetAddr, Length(IP), PF_Inet);
result:=p^.h_name;
except
result:='';
end;
end;function 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是192.168.0.1
struct hostent FAR * gethostbyname(
const char FAR * name // 指向待解析机器名的指针
);
函数返回指向的hostent结构体的指针。MSDN中该结构提的定义如下:
struct hostent {
char FAR * h_name; //目标计算机的正式名称
char FAR * FAR * h_aliases; //目标计算机的别名
short h_addrtype; //返回的目标计算机的地址类别
short h_length; //每个地址段的长度(字节)
char FAR * FAR * h_addr_list; //目标计算机分段地址的列表
};
Delphi 用记录THostEnt对此结构体作了如下封装;
PHostEnt=^THostEnt;
{$EXTERNALSYM hostent}
hostent=record
h_name:PChar;
h_aliases:^PChar;
h_addrtype:SmallInt;
h_length:Smallint;
case byte of
0:(h_addr_list:^PChar);
1:(h_addr:^Pchar);
end;
end;
THostEnt=hostent;明白了吗??
进制转换可通过API函数inet_addr来实现。
得到DNS有这样一个办法你访问注册表这个位置HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters一般的代理都能看到值