C# Ping的例子,可用于测试网络,延迟xx毫秒 C#编写网站测速

时间:2023-01-06 10:41:56

C#编写网站测速

WebClient wcl = new WebClient();
Stopwatch spwatch = new Stopwatch();
spwatch.Start();
byte[] resultBytes = wcl.DownloadData(new Uri(textBox1.Text));
spwatch.Stop();
MessageBox.Show(spwatch.Elapsed.ToString());
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.NetworkInformation; namespace PingExample
{
public partial class Form1 : Form
{
#region 设计
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txt_IPAddress = new System.Windows.Forms.TextBox();
this.lst_PingResult = new System.Windows.Forms.ListBox();
this.btn_StartPing = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "远程主机IP:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(, );
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(, );
this.label2.TabIndex = ;
this.label2.Text = "测试结果:";
//
// txt_IPAddress
//
this.txt_IPAddress.Location = new System.Drawing.Point(, );
this.txt_IPAddress.Name = "txt_IPAddress";
this.txt_IPAddress.Size = new System.Drawing.Size(, );
this.txt_IPAddress.TabIndex = ;
//
// lst_PingResult
//
this.lst_PingResult.FormattingEnabled = true;
this.lst_PingResult.ItemHeight = ;
this.lst_PingResult.Location = new System.Drawing.Point(, );
this.lst_PingResult.Name = "lst_PingResult";
this.lst_PingResult.Size = new System.Drawing.Size(, );
this.lst_PingResult.TabIndex = ;
//
// btn_StartPing
//
this.btn_StartPing.Location = new System.Drawing.Point(, );
this.btn_StartPing.Name = "btn_StartPing";
this.btn_StartPing.Size = new System.Drawing.Size(, );
this.btn_StartPing.TabIndex = ;
this.btn_StartPing.Text = "Ping";
this.btn_StartPing.UseVisualStyleBackColor = true;
this.btn_StartPing.Click += new System.EventHandler(this.btn_StartPing_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.btn_StartPing);
this.Controls.Add(this.lst_PingResult);
this.Controls.Add(this.txt_IPAddress);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "ping 类的用法";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txt_IPAddress;
private System.Windows.Forms.ListBox lst_PingResult;
private System.Windows.Forms.Button btn_StartPing;
#endregion public Form1()
{
InitializeComponent();
} private void btn_StartPing_Click(object sender, EventArgs e)
{
this.lst_PingResult.Items.Clear();
//远程服务器IP
string ipStr = txt_IPAddress.Text.ToString().Trim();
//构造Ping实例
Ping pingSender = new Ping();
//Ping 选项设置
PingOptions options = new PingOptions();
options.DontFragment = true;
//测试数据
string data = "";
byte[] buffer = Encoding.ASCII.GetBytes(data);
//设置超时时间
int timeout = ;
//调用同步 send 方法发送数据,将返回结果保存至PingReply实例
PingReply reply = pingSender.Send(ipStr, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
lst_PingResult.Items.Add("答复的主机地址:" + reply.Address.ToString());
lst_PingResult.Items.Add("往返时间:" + reply.RoundtripTime);
lst_PingResult.Items.Add("生存时间(TTL):" + reply.Options.Ttl);
lst_PingResult.Items.Add("是否控制数据包的分段:" + reply.Options.DontFragment);
lst_PingResult.Items.Add("缓冲区大小:" + reply.Buffer.Length);
}
else
lst_PingResult.Items.Add(reply.Status.ToString());
}
}
}

C# Ping的例子,可用于测试网络,延迟xx毫秒 C#编写网站测速的更多相关文章

  1. &lpar;转&rpar;用C&num;实现实现简单的 Ping 的功能,用于测试网络是否已经连通

    本文转载自:http://blog.csdn.net/xiamin/archive/2009/02/14/3889696.aspx 用C#实现实现简单的 Ping 的功能,用于测试网络是否已经联通 1 ...

  2. C&num;实现简单的 Ping 的功能,用于测试网络是否已经联通

    /// <summary> /// 是否能 Ping 通指定的主机 /// </summary> /// <param name="ip">ip ...

  3. linux 测试网络延迟

    1.在A服务器上运行qperf  &作为服务器节点,由其他服务器来连接测试,默认监听tcp的19765端口.

  4. 网站测速、ping

    1.17ce 2. 360奇云测 3.http://ping.chinaz.com/ 效果图:

  5. JS 测试网络速度与网络延迟

    一.延迟与网速 通过js加载一张1x1的极小图片,测试出图片加载的所用的时长.如果换一个几百KB的图片,则可心用来计算下载网速 document.write('<input type=&quot ...

  6. 网络延迟查看器 Network latency view 1&period;4

    这是个用于查看网络延迟/ip/主机/地区的工具,内外网通吃,外网可通过这里下载csv以显示国家(地区) 可以自己决定winpcap或者原始套接字进行捕捉 如果只扫描内网推荐angryip 这是款发布在 ...

  7. Android IOS WebRTC 音视频开发总结(五六)-- 如何测试网络性能?

    本文主要介绍如何测试网络性能,文章来自博客园RTC.Blacker,欢迎关注微信公众号blacker,更多详见www.rtc.help 网络性能直接决定了视频通话效果,比如qq,很多时候我们我们觉得通 ...

  8. 超级 Ping 监测工具——为您的网络状态保驾护航

    关于 Ping Ping 是一个网络命令,主要是用于确定本地主机是否能与另一台主机交换(发送与接收)数据.根据返回的信息,就可以推断 TCP/IP 参数是否设置得正确以及运行是否正常.正常情况下,Pi ...

  9. linux ping IP地址与telnet 测试IP端口

    ping命令是不能够测试端口的,ping只是测试网络联接状况以及信息包发送和接收状况. 格式:ping IP地址或主机名 [-t] [-a] [-n count] [-l size] 参数含义:-t不 ...

随机推荐

  1. PHPCMS V9教程之快速入门

    这篇文章要为大家来介绍PHPCMS V9这个系统的一些基本知识,PHPCMS是基于面向对象的,严格的安装MVC开发模式开发的CMS系统,同时他还是一个非 常不错的PHP框架.下面我们一起看一下PHPC ...

  2. 【沙茶了&plus;筛选保存最大质因数】【HDU2136】Largest prime factor

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. PADS Layout怎样放置间距一样的同一种元件

    少数元件的话,栅格设置是最好的,即将栅格设置成你要放置元件的间距,然后逐个移动元件放置.如果元件几十上百个,这样做就累死人了,此时就得设置阵列.按顺序选择你要放置的元件-右键-create arry, ...

  4. 上传下载文件, 同时部署在webapps下, 而不是项目下,防止重新部署tomcat, 上传文件消失

    前端上传 <a href='javascript:upload("+data[i].id+")' title='Upload Report'> <img src= ...

  5. 创建pandas和sqlalchemy的j交互对象,方便于日常的数据库的增删改查&lpar;原创&rpar;

    #导入第三方库sqlalchemy的数据库引擎 from sqlalchemy import create_engine #导入科学计算库 import pandas as pd #导入绘图库 imp ...

  6. Win 7&sol;10 安装Oracle 11g

    两个系统安装oracle的过程基本一致,注意安装时选桌面类(没有试过server,只有server类的操作系统选择server类) 安装过程:https://jingyan.baidu.com/alb ...

  7. &period;NET 同步与异步 之 Mutex (十二)

    本随笔续接:.NET 同步与异步 之 线程安全的集合 (十一) 本随笔 及 接下来的两篇随笔,将介绍 .NET 同步与异步系列 的最后一个大块知识点:WaitHandle家族. 抽象基类:WaitHa ...

  8. 这里有一篇简单易懂的webSocket 快到碗里来~

    这篇文章是我在学习的时候看到的  刚开始还不是很理解  后来自己百度 又问了一些人  回过头在看这篇文章 真的挺好的 但是原创已经不知道是谁了  转载哦~~~ -------------------- ...

  9. jmeter中测试接口

    本文主要介绍在jmeter中测试接口:主要从以下几个方面进行说明: 1.jmeter简介 2.jmeter怎么做接口测试 3.jmeter进行参数化的几种形式 4.jmeter中处理乱码方法 5.jm ...

  10. Tomcat 启动成功后报 INFO &lbrack;Timer-0&rsqb; org&period;apache&period;catalina&period;loader&period;WebappClassLoaderBase&period;checkStateForResourceLoading Illegal access&colon;

    Tomcat 启动成功后报 INFO [Timer-0] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceL ...