using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
namespace GetNetworkIpAddress
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Gets the machine names that are connected on LAN
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 = "";
while ((line = streamReader.ReadLine()) != null)
{
if (line.StartsWith("\\"))
{
string pcname = line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper();
string myIP = Convert.ToString(System.Net.Dns.GetHostByName(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper()).AddressList[0].ToString());
string fullname = "PC Name : "+pcname + " IP Address : " + myIP;
listBox1.Items.Add(fullname);
}
}
streamReader.Close();
netUtility.WaitForExit(1000);
}
}
}
See Also :
- How to show hidden theme in win 7.
- How To Make "Star Design" In CMD Windows.
- How to get color name in C#.Net
- How to change Logon Message in Windows7
- How to find the product Key of Windows XP CD
--
/\/ir@\/ <(.'.)>
hi.. am getting error in convert.tostring() method.. can u plz help
ReplyDeletecan you show me what actual error comes. ? so i can help you
ReplyDeletei have error in
ReplyDelete((line = streamReader.ReadLine()) != null)
Hi,
DeleteCan you tell me which error you are facing. ?
i have error in
ReplyDelete((line = streamReader.ReadLine()) != null)
ur very very silly guy... i think u have an error... man ask u twice - what is error!!!???
Deletehi sir. i'm trying to get all computer name and ip connected to the lan through your code. but i can't get anything. hope you can help me about it sir. thank you.
ReplyDeleteThe "net.exe view" command doesn't work on current windows computers. The output is:
ReplyDeleteSystem error 384 has occurred.
You can't connect to the file share because it's not secure. This share requires the obsolete SMB1 protocol, which is unsafe and could expose your system to attack.
Your system requires SMB2 or higher. For more info on resolving this issue, see: https://go.microsoft.com/fwlink/?linkid=852747