Breaking News
Loading...
Sunday, 6 July 2014

How to Get ALL Computer Name and IP Address from the LAN connection.




Download Project : GetNetworkIpAddress.zip
       
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 :

  Follow Me On Facebook

--
/\/ir@\/  <(.'.)>

5 comments:

  1. hi.. am getting error in convert.tostring() method.. can u plz help

    ReplyDelete
  2. can you show me what actual error comes. ? so i can help you

    ReplyDelete
  3. i have error in
    ((line = streamReader.ReadLine()) != null)

    ReplyDelete
    Replies
    1. Hi,

      Can you tell me which error you are facing. ?

      Delete
  4. i have error in
    ((line = streamReader.ReadLine()) != null)

    ReplyDelete

Thanks for comment

 
Toggle Footer