Skip to content

Netstat GUI

chris

Asked Feb 10, 2009, 10:03 AM EST3 answers
Share
LinkedInX
Basically I am making a netstat GUI. netstat is a command in the cmd that shows all the IP addresses you are connected with. I coded my app, but for some reason it will only show one IP not all the one's I am connected to.

Here is my code:

        private void button1_Click(object sender, EventArgs e)
        {
            iplist.ReadOnly = true;
            IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
            IPEndPoint[] endPoints = ipProperties.GetActiveTcpListeners();
            TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();
            //List IPS

            foreach (TcpConnectionInformation info in tcpConnections)
            {
                iplist.Text = ("Local : " + info.LocalEndPoint.Address.ToString()
                + ":" + info.LocalEndPoint.Port.ToString()
                + "\nRemote : " + info.RemoteEndPoint.Address.ToString()
                + ":" + info.RemoteEndPoint.Port.ToString()
                + "\nState : " + info.State.ToString() + "\n\n");
            }

        }

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Bump, anyone know of why this isn't working properly?
    0
  • 0
    It seems to me that you are resetting the iplist.Text for each loop you are doing..
    Instead of

    iplist.Text = ("Local : " + ...

    do

    iplist.Text += ("Local : " + ...

    i.e. add the plus-sign before "=". 
    Let me know if it works ;)
    You should by any case create a StringBuilder instead, and apply the content of this to ipList.Text. This is more efficient..   

     
    0
  • 1 short reply
    • 0
      Ugh, still no one?
      0