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@\/  <(.'.)>

8 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
    Replies
    1. ur very very silly guy... i think u have an error... man ask u twice - what is error!!!???

      Delete
  5. hi 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.

    ReplyDelete
  6. The "net.exe view" command doesn't work on current windows computers. The output is:

    System 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

    ReplyDelete

Thanks for comment

 
Toggle Footer