function MyGetHostByAddr(const AAddress: string): string; var Host: PHostEnt; LAddr: Longint; begin LAddr := inet_addr(PChar(AAddress)); Host := GetHostByAddr(@LAddr, SizeOf(LAddr), AF_INET); if Host <> nil then begin result := Host^.h_name; end; end;
function MyGetHostByAddr(const AAddress: string): string; var Host: PHostEnt; LAddr: Longint; begin LAddr := inet_addr(PChar(AAddress)); Host := GetHostByAddr(@LAddr, SizeOf(LAddr), AF_INET); if Host <> nil then begin result := Host^.h_name; end; end;
uses winsock;后直接用就是了
比如我指定IP为'192.168.0.1'
我想知道这个ip的主机的名字
能给个例子吗(一小段代码,我对DElphi不是很熟悉)
var
Host: PHostEnt;
LAddr: Longint;
begin
LAddr := inet_addr(PChar(AAddress));
Host := GetHostByAddr(@LAddr, SizeOf(LAddr), AF_INET);
if Host <> nil then begin
result := Host^.h_name;
end;
end;
var
Host: PHostEnt;
LAddr: Longint;
begin
LAddr := inet_addr(PChar(AAddress));
Host := GetHostByAddr(@LAddr, SizeOf(LAddr), AF_INET);
if Host <> nil then begin
result := Host^.h_name;
end;
end;
但出了错