开发者

Getting names and IP addresses of the computers over LAN

开发者 https://www.devze.com 2023-01-27 03:00 出处:网络
How can I know which computers are connected with LAN (names and IP addre开发者_开发技巧ss), using Vb.Net code?

How can I know which computers are connected with LAN (names and IP addre开发者_开发技巧ss), using Vb.Net code? Thanks Furqan


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.


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);
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消