远程控制篇:
通过机器名得到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地址得到机器名
function iptoname(ip:string):string;
var
WSAData:TWSAData;
p:PHostEnt;
.NETAddr: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;
---------------------------------------------------------
湖北襄樊 官本和(Mailto:gbh12345@china.com">gbh12345@china.com) 2001.4
详见主页源程序:
Delphi21cn.yeah.net">http://delphi21cn.yeah.net
http://personal.hb.cninfo.net/~gbh
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-988206/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752043/viewspace-988206/
1万+

被折叠的 条评论
为什么被折叠?



