首页  编辑  

如何取得局域网内的计算机名?

Tags: /超级猛料/Network.网络通讯/LAN/   Date Created:
Function GetNameByIP(MIP:string; var Name:string):boolean;
var
 PHt:PHostEnt;
 WSData: TWSAData;
 i:Word;
 j:integer;
 k:u_long;
begin
 result:=false;
 i:=MAKEWORD(1,1);
 if WSAStartup(i,WSData)<>0 then exit;
 k:=inet_addr(PChar(MIP));
 PHt:=gethostbyaddr(@k,4,PF_INET);
 if PHt=nil then begin
    j:=WSAGetLastError;
    Name:='Error:'+inttostr(j-WSABASEERR);
 end else begin
    Name:=PHt.h_name;
    result:=true;
 end;
 WSACleanup;
end;