How to Get ALL Computer Name and IP Address from the LAN connection.
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)