Не могу получит IP адреса ПК в сети, при компиляции вылетает ошибка: Необработанное исключение типа "System.Net.Sockets.SocketException" в System.dll Дополнительные сведения: Запрошенное имя верно, но данные запрошенного типа не найдены.
Вот код:
Код |
listBox1.Items.Clear();
Process netUtility = new Process();
netUtility.StartInfo.FileName = "net.exe";
netUtility.StartInfo.CreateNoWindow = true;
netUtility.StartInfo.Arguments = "view";
netUtility.StartInfo.RedirectStandardOutput = true;
netUtility.StartInfo.UseShellExecute = false;
netUtility.StartInfo.RedirectStandardError = true;
netUtility.Start();
StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);
string line = "";
//IPAddress[] addrs = Dns.GetHostByName(line).AddressList;
//foreach (IPAddress addr in addrs) // { while ((line = streamReader.ReadLine()) != null) {
if (line.StartsWith("\\")) {
listBox1.Items.Add(line.Substring(2));
string adddr = line.Substring(2); IPAddress[] addrs = Dns.GetHostByName(adddr).AddressList;// ошибка здесь
foreach (IPAddress addr in addrs) { listBox2.Items.Add(addr.ToString()); } } }
streamReader.Close(); netUtility.WaitForExit(1000);
|
|