js获取计算机名,C#获取当前域的计算机列表

/// /// 获取当前域的计算机列表 /// /// public List GetAllLocalMachines() { //局域网计算机列表 List machineList = new List();
Process p = new Process();
p.StartInfo.FileName = "net";
p.StartInfo.Arguments = "view";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("exit");
StreamReader reader = p.StandardOutput;
for (string line = reader.ReadLine(); line != null; line = reader.ReadLine()) { line = line.Trim();
if (line.StartsWith(@"\\")) { string name = line.Substring(2).Trim();
//如果有路由器,会列出路由器,但是获取不到IP地址,会报错
try { LocalMachine localMachine = new LocalMachine();
localMachine.MachineIP = Dns.GetHostEntry(name).AddressList[0].ToString();
localMachine.MachineName = name;
machineList.Add(localMachine); } catch { //MessageBox.Show("Error!"); }
}
}
return machineList; }
Tags:  获取计算机名称 如何获取计算机名 获取计算机名 js获取计算机名

延伸阅读

最新评论

发表评论