远程控制篇:
通过机器名得到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; 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;
---------------------------------------------------------
湖北襄樊 官本和([email protected]) 2001.4 详见主页源程序: http://delphi21cn.yeah.net http://personal.hb.cninfo.net/~gbh 
|