日期:2014-05-18 浏览次数:20847 次
private void GetAllComputer()
{
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry dom in root.Children)
{
string name = dom.Name;
this.comboBox1.Items.Add(name);
foreach (DirectoryEntry com in dom.Children)
{
if (com.SchemaClassName.Equals("Computer"))
{
string coms = com.Name;
comboBox2.Items.Add(coms);
IPHostEntry iphe = Dns.GetHostEntry(com.Name);
foreach (IPAddress ip in iphe.AddressList)
{
if(ip.AddressFamily==AddressFamily.InterNetwork)
comboBox3.Items.Add(ip.ToString());
}
}
}
}
}
public void send(string message,string ip)
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress ipAddre = IPAddress.Parse(ip);
Byte[] by = Encoding.UTF8.GetBytes(message);
IPEndPoint ep = new IPEndPoint(ipAddre, 11000);
s.SendTo(by, ep);
}