zoukankan      html  css  js  c++  java
  • 测试局域网内网络数据

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

        }   

      }

    }

  • 相关阅读:
    mybatis
    Hello mybatis
    linux各种终端类型的区别和概念
    页面对象的定位
    laravel 操作 redis
    Python应用与实践
    Mysql与Oracle区别
    PHP 中 call_user_func 函数 和 call_user_func_array 函数的区别
    php依赖注入
    Linux/Unix 怎样找出并删除某一时间点的文件
  • 原文地址:https://www.cnblogs.com/JueXiaoQiang/p/6747704.html
Copyright © 2011-2022 走看看