//远程登陆
function NetConnect(HostName,User,Pass:string):boolean;
var
lpNetRes: TNetResourceA;
ret:dword;
begin
//登录到目标计算机(要有关机权限的用户:如管理员)
FillChar(lpNetRes, SizeOf(lpNetRes), 0);
lpNetRes.dwScope := RESOURCE_GLOBALNET;
lpNetRes.dwType := RESOURCETYPE_ANY;
lpNetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
lpNetRes.lpRemoteName := PChar('\\' + HostName+'\IPC$');
ret:=WNetAddConnection2(lpNetRes, PChar(Pass), PChar(User), 0);
if ret<>0 then
result:=false
else result:=true;
end;
//退出远程登陆
function NetConnectCancel(HostName:string):boolean;
begin
result:=WNetCancelConnection2(PChar('\\'+HostName+'\IPC$'),0,true)=0;
end;
function LocalIP : string; //本机IP地址
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
Var
phe : PHostEnt;
// pptr : PaPInAddr;
Buffer : array [0..63] of char;
//I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
result:=inet_ntoa(pinaddr(phe^.h_addr_list^)^);//局域网 IP
// pptr := PaPInAddr(Phe^.h_addr_list);
//I := 0;
{while pptr^[I] <> nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));//上网IP
Inc(I);
end;
}
WSACleanup;
end;
function GetHostName(IP : string):string; //读取主机名
var
pH:PHostent;
data:twsadata;
ii:dword;
begin
WSAStartup($101, Data);
ii:=inet_addr(pchar(ip));
pH:=gethostbyaddr(@ii,sizeof(ii),PF_INET);
if (ph<>nil) then
result:=pH.h_name
else
result:='';
WSACleanup;
end;