using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.DirectoryServices;
namespace Demo
{
public class Demo
{
public Demo() { }
private void GroupInfo()
{
DirectoryEntry MainGroup = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry domain in MainGroup.Children)
{
//this.listView1.Items.Add(domain.Name);此代码获取局域网内的所有机器名
//当局域网内有授权用户是,即TA已经登录成功,获得权限
//System.Net.Dns.GetHostName();获取用户名。
}
}
//通过机器名获取相应IP
private void ComputerInfo(String strname)
{
try
{
DirectoryEntry MainGroup = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry domain in MainGroup.Children)
{
if (domain.Name == strname)
{
foreach (DirectoryEntry pc in domain.Children)
{
IPAddress[] ip = Dns.GetHostAddresses(pc.Name);
//this.listView2.Items.Add(pc.Name + ip[0].ToString());获取IP
}
}
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
}
}