• 测试局域网内网络数据


    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;

    namespace winPing

      {    

        public partial class Form1 : Form    

        {        

            public Form1()        

            {            

              InitializeComponent();        

            }

                private void button1_Click(object sender, EventArgs e)        

    {            

    try             {   

                  Ping p = new Ping();//实例化ping          

           PingOptions po = new PingOptions();       

              po.DontFragment = true;//是否设置数据分段         

            string myInfo = "asdfghjklqwertyuiopzxcvbnm";//发送信息       

              byte[] buffer = Encoding.ASCII.GetBytes(myInfo);       

              int timeOut = 120;//超时时间                 //发送数据包        

             PingReply pr = p.Send(this.txtSerIP.Text, timeOut, buffer, po);       

              if (pr.Status == IPStatus.Success)//判断是否发送成功         

            {                     this.textBox1.Text = pr.RoundtripTime.ToString();//耗费时间         

                this.textBox2.Text = pr.Options.Ttl.ToString();//路由节点数             

            this.textBox3.Text = (pr.Options.DontFragment ? "发生分段" : "为发生分段");          

               this.textBox4.Text = pr.Buffer.Length.ToString();//缓冲大小            

             int timer = int.Parse(this.textBox1.Text);            

             if (timer < 20)                    

    {                        

    this.textBox5.Text = "网络良好";              

           }                     else                 

        {                       

      this.textBox5.Text = "网络通畅";              

           }              

       }                 else                

    {                

         MessageBox.Show("无法ping通", "提示");         

            }       

          }             catch (Exception ey)             {                 MessageBox.Show(ey.Message);             }         }

            private void Form1_Load(object sender, EventArgs e)  

           { 

        string name=Dns.GetHostName();       

            IPHostEntry ipaddress= Dns.GetHostByName(name);     

            IPAddress ipa = ipaddress.AddressList[0];     

            this.txtMyIP.Text = ipa.ToString();     

        }   

      }

    }

  • 相关阅读:
    Markdown标签
    macbook使用
    git的使用
    HTTPS的原理
    javascript中的对象
    javascript中this的指向问题
    javascript中的闭包
    javaScript中的return、break和continue
    Promise对象
    ORACLE_11G归档空间满,由于数据库装完后使用的是默认空间是闪回区
  • 原文地址:https://www.cnblogs.com/JueXiaoQiang/p/6747704.html
Copyright © 2020-2023  润新知