请问怎样用C#检测到本机的局域网IP和列出整个局域网的IP?

newball 2003-09-29 07:25:48
如题,谢谢.
...全文
160 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ajex 2003-10-10
  • 打赏
  • 举报
回复
using System;
using System.DirectoryServices;
using System.Net;

class TestClass
{
static void Main (string[] args)
{
ShowComputers();
}
public static void ShowComputers()
{
//or use "WinNT://your_domain_name"
DirectoryEntry root = new DirectoryEntry("WinNT:"); DirectoryEntries domains = root.Children;
domains.SchemaFilter.Add("domain");
foreach (DirectoryEntry domain in domains)
{
Console.WriteLine(domain.Name);
DirectoryEntries computers = domain.Children;
computers.SchemaFilter.Add("computer");
foreach (DirectoryEntry computer in computers)
{
Console.WriteLine("\t" + computer.Name);
IPHostEntry iphe = Dns.GetHostByName(computer.Name);
foreach (IPAddress ip in iphe.AddressList)
{
Console.WriteLine("\t\t" + ip);
}
DirectoryEntries users = computer.Children;
}
}
}

}
ajex 2003-10-10
  • 打赏
  • 举报
回复
用api是一种方法.但是.net下有更好的选择:

可以参考:http://www.microsoft.com/china/community/program/originalarticles/TechDoc/DirectoryEntry.mspx
能过主机名获得ip可以用system.net.dns来搞定.
binbin2000 2003-10-10
  • 打赏
  • 举报
回复
关注:
to niaoren(阿青):
可以写出代码吗。
newball 2003-09-30
  • 打赏
  • 举报
回复
难道C#命令不可以吗?
niaoren 2003-09-29
  • 打赏
  • 举报
回复
用API函数吧
newball 2003-09-29
  • 打赏
  • 举报
回复
up

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧