虽然可以启动命令行工具,但我建议使用Ping class
.Net Framework 4.0(Ping 类)中的可用工具
这是对 MSDN 示例的修改
using System.Net.NetworkInformation;
using System.Diagnostics; // for demo purposes only
private void PingCommand_Click(object sender, EventArgs e)
{
Ping pingSender = new Ping ();
PingOptions options = new PingOptions ();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes (data);
int timeout = 120;
string ipOrHost = "80.108.20.100"; // or access your textbox
//string ipOrHost = txtIP.Text;
PingReply reply = pingSender.Send (ipOrHost, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Debug.WriteLine ("Address: " + reply.Address.ToString ());
Debug.WriteLine ("RoundTrip time: " + reply.RoundtripTime);
Debug.WriteLine ("Time to live: " + reply.Options.Ttl);
Debug.WriteLine ("Don't fragment: " + reply.Options.DontFragment);
Debug.WriteLine ("Buffer size: " + reply.Buffer.Length);
}
}
如果您确实需要启动任何命令行工具,您可以查看Process
和ProcessInfo
类(MSDN上的示例代码)