获得在C#中所有连接的电脑的IP地址 [英] get ip address of all connected pc in c#
问题描述
可能重复:结果
的让我的电脑上所有的PC,它连接在局域网中使用C#
块引用>
这是我的code.I只给我的计算机的IP地址,但我想所有IP的计算机地址这是lan.also我给解决错误在此代码连接。请给我一份有代码的修改方案。
静态无效的主要(字串[] args)
{
的System.Diagnostics.Process P =新的System.Diagnostics.Process();
p.StartInfo.FileName =CMD;
p.StartInfo.UseShellExecute = FALSE;
p.StartInfo.Arguments =/ C网的观点;
p.StartInfo.RedirectStandardOutput = TRUE;
p.Start();
字符串输出= p.StandardOutput.ReadToEnd();
的char [] =分隔符字符新[] {'\\\
'};
字符串strHostName =的String.Empty;
的String [] S = output.Split(分隔符,StringSplitOptions.RemoveEmptyEntries);
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
ip地址[]地址= ipEntry.AddressList;
p.WaitForExit();
INT Z = s.Length - 5;
的String [] = STR1新的字符串[Z]。
INT I = 0;
的char [] saperator = {''};
为(INT J = 3; J< s.Length - 2; J ++,我++)
{
STR1 [I] =(S [J]的ToString( ))斯普利特(saperator)[0]。
Console.WriteLine(IP地址{0}:{1},我,地址[I]的ToString());
}
//Console.WriteLine(output);
到Console.ReadLine();
}
解决方案我不是完全是一个专业,但我想你需要的是被称为端口扫描程序是什么,你可以实现一个端口扫描器的非常基本的功能集成到你的应用程序和网络中读取所有现场IPS
一解决办法是:
HTTP://www.geekpedia .COM / tutorial142_Creating-A-端口扫描仪与 - Csharp.html
他们甚至有可供下载网站上的代码。还没有尝试过下载它强悍。 :)
Possible Duplicate:
get ip address of all pc on my pc which is connected in lan in c#This is my code.I give only ip address of my computer but i want to ip address of all computer which is connected in lan.also i give the troubleshoot error in this code. please give me the solution with changes of code.
static void Main(string[] args) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "cmd "; p.StartInfo.UseShellExecute = false; p.StartInfo.Arguments = "/C net view"; p.StartInfo.RedirectStandardOutput = true; p.Start(); String output = p.StandardOutput.ReadToEnd(); char[] delimiters = new char[] { '\n' }; String strHostName = string.Empty; string[] s = output.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); IPHostEntry ipEntry = Dns.GetHostEntry(strHostName); IPAddress[] addr = ipEntry.AddressList; p.WaitForExit(); int z = s.Length - 5; string[] str1 = new string[z]; int i = 0; char[] saperator = { ' '}; for (int j = 3; j < s.Length - 2; j++, i++) { str1[i] = (s[j].ToString()).Split(saperator)[0] ; Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString()); } //Console.WriteLine(output); Console.ReadLine(); }
解决方案Im not exactly a professional but i think what you need is called a port scanner, you can implement the very basic functionality of a port scanner into your app and read all the live ips in your network
one solution would be: http://www.geekpedia.com/tutorial142_Creating-a-Port-Scanner-with-Csharp.html
they even have code available for download on the site. haven't tried downloading it tough. :)
这篇关于获得在C#中所有连接的电脑的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!