Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.IO;
- using System.Collections;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- Ping pingSender = new Ping();
- IPAddress myself;
- int Req_num = 0;
- int Rec_num = 0;
- int nRec_num = 0;
- public Form1()
- {
- InitializeComponent();
- textBox3.BackColor = Color.White;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- IPHostEntry ihe = Dns.GetHostByName(textBox1.Text);
- myself = ihe.AddressList[0];
- timer1.Start();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- P_component();
- }
- void P_component()
- {
- string data = RandomString(int.Parse(numericUpDown1.Value.ToString()));
- byte[] buffer = Encoding.ASCII.GetBytes(data);
- int timeout = 1200;
- PingReply reply = pingSender.Send(myself, timeout, buffer);
- if (reply.RoundtripTime != 0)
- {
- textBox3.AppendText("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + myself.ToString() + " " + reply.RoundtripTime.ToString() + " ms \r\n");
- Req_num++;
- req_num.Text = Req_num.ToString();
- Rec_num++;
- rec_num.Text = Rec_num.ToString();
- }
- else
- {
- textBox3.AppendText("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + myself.ToString() + " is not responding \r\n");
- Req_num++;
- req_num.Text = Req_num.ToString();
- nRec_num++;
- nrec_num.Text = nRec_num.ToString();
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- timer1.Stop();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (checkBox1.Checked)
- {
- if (File.Exists("Logs"))
- saveLog();
- else
- {
- logs_Create();
- saveLog();
- }
- }
- textBox3.Clear();
- Req_num = 0;
- req_num.Text = "0";
- Rec_num = 0;
- rec_num.Text = "0";
- nRec_num = 0;
- nrec_num.Text = "0";
- }
- private string RandomString(int size)
- {
- StringBuilder builder = new StringBuilder();
- Random random = new Random();
- char ch;
- for (int i = 0; i < size; i++)
- {
- ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
- builder.Append(ch);
- }
- return builder.ToString();
- }
- private void saveLog()
- {
- string filename = "Logs\\" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".log";
- System.IO.StreamWriter file = new System.IO.StreamWriter(filename);
- file.WriteLine("Log was saved at: " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss dddd"));
- file.WriteLine("Domain: " + textBox1.Text);
- file.WriteLine("IP: " + myself.ToString());
- file.WriteLine("Ping with " + numericUpDown1.Value.ToString() + " bytes");
- file.WriteLine("Requests sent: " + Req_num.ToString());
- file.WriteLine("Answer received: " + Rec_num.ToString());
- file.WriteLine("Answer not received: " + nRec_num.ToString());
- file.WriteLine(textBox3.Text);
- file.Close();
- }
- private void logs_Create()
- {
- Directory.CreateDirectory("Logs");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment