using System; using System.Net.NetworkInformation; using System.Windows.Forms; namespace Pong { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { textBox1.Text = "www.yandex.ru"; numericUpDown1.Text = "32"; numericUpDown2.Text = "120"; numericUpDown3.Text = "100"; numericUpDown3.Text = "1"; } private void buttonPing_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0) MessageBox.Show("Введите адрес"); //проверка заполнения полей else if (numericUpDown1.Text.Length == 0) MessageBox.Show("Введите размер пакета"); else if (numericUpDown2.Text.Length == 0) MessageBox.Show("Введите время ожидания"); else if (numericUpDown3.Text.Length == 0) MessageBox.Show("Введите время жизни пакета"); else { try { string adress; // адрес byte[] packetBuffer; // число байт int timeout; // время ожидания int TTL; // время жизни пакета int tries; adress = textBox1.Text.ToString(); packetBuffer = new byte[int.Parse(numericUpDown1.Text.ToString())]; timeout = int.Parse(numericUpDown2.Text.ToString()) * 1000; TTL = int.Parse(numericUpDown3.Text.ToString()); tries = (int)numericUpDown4.Value; Ping ping = new Ping(); PingReply reply; PingOptions options = new PingOptions(TTL, checkBox1.Checked); // задание параметров richTextBoxMain.Text = $"Обмен пакетами с {adress} с {packetBuffer.Length} байтами данных:\n"; for (int i = 0; i < tries; i++) { reply = ping.Send(adress, timeout, packetBuffer, options); switch (reply.Status) { case IPStatus.Success: richTextBoxMain.Text += $"Ответ от {reply.Address}: число байт = {reply.Buffer.Length} время= {reply.RoundtripTime} мс TTL= {reply.Options.Ttl} \n"; break; case IPStatus.TimedOut: richTextBoxMain.Text += "Превышено время ожидания... \n"; break; default: richTextBoxMain.Text += $"Обмен пакетами прерван: {reply.Status.ToString()} \n"; break; } } } catch { MessageBox.Show("Ошибка. Некорректное заполнение полей"); } } } private void buttonClear_Click(object sender, EventArgs e) { richTextBoxMain.Text = ""; } } }