哪位大哥有获取局域网内所有连接路由器的机器ip的代码

ai19811125 2009-09-28 05:24:23
如题
...全文
687 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
535cheng110 2009-09-30
  • 打赏
  • 举报
回复
不知道这个是不是你想要的

http://webservices.ctocio.com.cn/net/269/9202269.shtml
csdn_风中雪狼 2009-09-28
  • 打赏
  • 举报
回复
学习
gisyellow 2009-09-28
  • 打赏
  • 举报
回复
占个位置,学习!
wuyq11 2009-09-28
  • 打赏
  • 举报
回复
DirectoryEntry root = new DirectoryEntry("WinNT:");
DirectoryEntries domains = root.Children;
domains.SchemaFilter.Add("domain");
foreach (DirectoryEntry domain in domains) {
IPHostEntry iphe = null;
try {
iphe = Dns.GetHostByName(computer.Name);
}
catch { }
}


string strIPAddress="192.168.1.";
int nStrat = Int32.Parse("1");
int nEnd =Int32.Parse("255");
for(int i=nStrat;i<=nEnd;i++)
{
string strScanIPAdd = strIPAddress +i.ToString();
IPAddress myScanIP = IPAddress.Parse(strScanIPAdd);
try
{
IPHostEntry myScanHost = Dns.GetHostByAddress(myScanIP);
string strHostName =myScanHost.HostName.ToString();
this.listBox2.Items.Add(strScanIPAdd+"->"+strHostName+"\r");
}
catch
{

}
}
http://www.codeproject.com/KB/IP/Network_Computers.aspx
CsToD 2009-09-28
  • 打赏
  • 举报
回复
可以首先获得本机的IP地址,然后把IP最后一位从0枚举到255,并Ping这些机器

但这样的效率较低,一般到多线程其速度才能让人接受,我推荐用net view命令:

Process p = new Process();
p.StartInfo.FileName = "net";
p.StartInfo.Arguments = "view";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
while (!p.StandardOutput.EndOfStream)
{
string s = p.StandardOutput.ReadLine();
if (s.StartsWith(@"\\"))
{
try
{
Console.WriteLine(Dns.GetHostByName(s.Substring(2, s.IndexOf(' ') - 1)).AddressList[0].ToString());
}
catch { }
}
}
shizhen_zhang 2009-09-28
  • 打赏
  • 举报
回复
没做过。关注……
HDNGO 2009-09-28
  • 打赏
  • 举报
回复
            IPAddress[] ipadd;
string hostname = Dns.GetHostName();
ipadd=Dns.GetHostAddresses(hostname);

foreach (IPAddress ip in ipadd)
{
MessageBox.Show(hostname);
MessageBox.Show(ip.ToString());
}

110,500

社区成员

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

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

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