using System; using System.Drawing; using System.Collections; using System.Windows.Forms; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; //Download by http://www.codefans.net namespace Ping { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { #region Form Data private System.Windows.Forms.TextBox txtHost; private System.Windows.Forms.Label lblHost; private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.Button btnPing; private System.Windows.Forms.NumericUpDown udCount; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.MainMenu mainMenu1; #endregion public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); txtHost.Text = "www.yahoo.com"; } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.txtHost = new System.Windows.Forms.TextBox(); this.btnPing = new System.Windows.Forms.Button(); this.lblHost = new System.Windows.Forms.Label(); this.listBox1 = new System.Windows.Forms.ListBox(); this.udCount = new System.Windows.Forms.NumericUpDown(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); // // txtHost // this.txtHost.Location = new System.Drawing.Point(40, 16); this.txtHost.Text = "192.168.0.2"; // // btnPing // this.btnPing.Location = new System.Drawing.Point(168, 40); this.btnPing.Size = new System.Drawing.Size(64, 20); this.btnPing.Text = "Ping"; this.btnPing.Click += new System.EventHandler(this.btnPing_Click); // // lblHost // this.lblHost.Location = new System.Drawing.Point(144, 16); this.lblHost.Size = new System.Drawing.Size(96, 20); // // listBox1 // this.listBox1.Location = new System.Drawing.Point(0, 72); this.listBox1.Size = new System.Drawing.Size(240, 170); // // udCount // this.udCount.Location = new System.Drawing.Point(48, 40); this.udCount.Minimum = new System.Decimal(new int[] { 1, 0, 0, 0}); this.udCount.Size = new System.Drawing.Size(48, 20); this.udCount.Value = new System.Decimal(new int[] { 4, 0, 0, 0}); // // label1 // this.label1.Location = new System.Drawing.Point(0, 16); this.label1.Size = new System.Drawing.Size(32, 20); this.label1.Text = "Addr:"; // // label2 // this.label2.Location = new System.Drawing.Point(0, 40); this.label2.Size = new System.Drawing.Size(40, 20); this.label2.Text = "Count:"; // // Form1 // this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.udCount); this.Controls.Add(this.listBox1); this.Controls.Add(this.lblHost); this.Controls.Add(this.btnPing); this.Controls.Add(this.txtHost); this.Menu = this.mainMenu1; this.MinimizeBox = false; this.Text = "Form1"; } #endregion /// <summary> /// The main entry point for the application. /// </summary> static void Main() { Application.Run(new Form1()); } private void btnPing_Click(object sender, System.EventArgs e) { string addr = txtHost.Text; IPHostEntry entry = null; try { entry = Dns.GetHostByName(addr); } catch( SocketException ) { } if (entry==null || entry.AddressList.Length == 0) { MessageBox.Show("Could not resolve " + addr); txtHost.Focus(); return; } lblHost.Text = entry.AddressList[0].ToString(); byte[] RequestData = Encoding.ASCII.GetBytes( new string('