哪位大哥有获取局域网内所有连接路由器的机器ip的代码
如题 --------------------编程问答--------------------IPAddress[] ipadd;--------------------编程问答-------------------- 没做过。关注…… --------------------编程问答-------------------- 可以首先获得本机的IP地址,然后把IP最后一位从0枚举到255,并Ping这些机器
string hostname = Dns.GetHostName();
ipadd=Dns.GetHostAddresses(hostname);
foreach (IPAddress ip in ipadd)
{
MessageBox.Show(hostname);
MessageBox.Show(ip.ToString());
}
但这样的效率较低,一般到多线程其速度才能让人接受,我推荐用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 { }
}
}
http://www.microsoft.com/china/community/program/originalarticles/TechDoc/DirectoryEntry.mspx
效果如下图:
--------------------编程问答-------------------- 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 --------------------编程问答-------------------- 占个位置,学习! --------------------编程问答-------------------- 学习 --------------------编程问答-------------------- 不知道这个是不是你想要的
http://webservices.ctocio.com.cn/net/269/9202269.shtml
补充:.NET技术 , C#