首页 > 代码库 > 测试局域网内网络数据

测试局域网内网络数据

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();     

    }   

  }

}

测试局域网内网络数据