|
private void button1_Click (object sender, System.EventArgs e)
{
int i = 1;
for (i = 1; i <254; i ++)
{
string pstr = "192.168.0." + i.ToString ();
string strRst = CmdPing (pstr);
listBox1.Items.Add (pstr + "___" + strRst);
}
}
private static string CmdPing (string strIp)
{
Process p = new Process ();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string pingrst;
p.Start ();
p.StandardInput.WriteLine ("ping -n 1" + strIp);
p.StandardInput.WriteLine ("exit");
string strRst = p.StandardOutput.ReadToEnd ();
if (strRst.IndexOf ("(0% loss)")! =-1)
pingrst = "connection";
else if (strRst.IndexOf ("Destination host unreachable.")! =-1)
pingrst = "Unable to reach destination host";
else if (strRst.IndexOf ("Request timed out.")! =-1)
pingrst = "Timeout";
else if (strRst.IndexOf ("Unknown host")! =-1)
pingrst = "Unable to resolve host";
else
pingrst = strRst;
p.Close ();
return pingrst;
}
When the above program is executed, the data in listBox1 is not displayed accordingly, but is displayed together after a long time. The time delay is unbearable. How can I display it accordingly? |
|