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. (转)用C#实现实现简单的 Ping 的功能,用于测试网络是否已经连通

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

  2. C#实现简单的 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=" ...

  6. 网络延迟查看器 Network latency view 1.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. 【Jenkins】Windows下安装&访问jenkins

    1. 下载jenkins.war包 下载地址:http://jenkins-ci.org/ 2. 之后在cmd里启动jenkins,命令如下: java -jar (放置war包路径,最好没有中文)j ...

  2. 编程之美--2. Trie树 (Trie图)

    #1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助, ...

  3. JavaEE SSH框架整合(四) 日志处理Spring结合 log4j、slf4j [转]

    1. 加入log4j和slf4j的jar包 2. web.xml: <context-param> <!--log4j配置地址 --> <param-name>lo ...

  4. C#测试web服务是否可用

    winform客户端经常需要调用webservice或者WCF进行数据交互,但是远程服务有可能不存在或者服务器不可用,客户端只能通过超时或者捕获到异常感知服务不可用.其实有一个COM借口可用快速的检测 ...

  5. OC语言类的本质和分类

    OC语言类的深入和分类 一.分类 (一)分类的基本知识  概念:Category  分类是OC特有的语言,依赖于类. 分类的作用:在不改变原来的类内容的基础上,为类增加一些方法. 添加一个分类: 文件 ...

  6. iOS开发网络篇—搭建本地服务器

    iOS开发网络篇—搭建本地服务器 一.简单说明 说明:提前下载好相关软件,且安装目录最好安装在全英文路径下.如果路径有中文名,那么可能会出现一些莫名其妙的问题. 提示:提前准备好的软件 apache- ...

  7. 创建.htaccess文件

    在linux下创建.htaccess文件非常简单,直接新建一个文件并重命名为.htaccess即可. 下面我来讲下如何在Window下创建.htaccess文件 一般在本地电脑上是无法建立 .htac ...

  8. POJ 3041 Asteroids 匈牙利算法,最大流解法,行列为点 难度:1

    http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector& ...

  9. ZJOI2015 一试。

    虽然早就知道会是这个结果,但是看到的成绩时候还是有些忧伤,奇迹果然还是没有发生. 想了想还是应该写篇博文 纪念一下这段经历. Day0: 报道之后直接去了宾馆,然后意外的发现冬令营时候的室友wxh就住 ...

  10. Create Linked Server SQL Server 2008

    From:http://www.jensbits.com/2010/11/10/create-linked-server-sql-server-2008/ http://www.c-sharpcorn ...