Furqan Sehgal
Furqan Sehgal

Reputation: 4997

Getting names and IP addresses of the computers over LAN

How can I know which computers are connected with LAN (names and IP address), using Vb.Net code? Thanks Furqan

Upvotes: 0

Views: 4430

Answers (2)

raja
raja

Reputation: 1

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    TcpClient tcpclnt;

    private void Form1_Load(object sender, EventArgs e)
    {
        String hostname = Dns.GetHostName();
        MessageBox.Show(hostname);
        IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());

        //IPHostEntry myipaddlist = Dns.GetHostByName(hostname);
      foreach(IPAddress ips in myipaddlist.AddressList)
        {
            MessageBox.Show(ipa.ToString());
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            tcpclnt = new TcpClient();
            MessageBox.Show("connecting");
            tcpclnt.Connect("ur ipadress", 8001);
            label1.Text = "connected";
        }
        catch (Exception ex)
        {
            MessageBox.Show("error" + ex.StackTrace);
        }
    }

Upvotes: 0

Jacob
Jacob

Reputation: 168

To my know-age this is not possible, I know you can retrieve data about the host but not the LAN. It may be possible if it is the DHCP Server in windows Server or ICS in XP. The best solution to offer is to ping all hosts in the local sub net. Something like ping 192.168.0-255.0-255.

Upvotes: 2

Related Questions