using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Net;using System.Net.NetworkInformation;
namespace PingIpAddress{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private Ping pingSender = new Ping(); private string strIP = ""; private void button1_Click(object sender, EventArgs e) { strIP = txtIP.Text; PingOptions pingOption = new PingOptions(); pingOption.DontFragment = true;
string data = "sendData:goodgoodgoodgoodgoodgood"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; PingReply reply = pingSender.Send(strIP, timeout, buffer); if (reply.Status == IPStatus.Success) { MessageBox.Show("能ping通 "); } else { MessageBox.Show("ping不通"); } } }}