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. flash的动态加载技术

    这里所说的动态加载技术, 主要是指代码模块(可以是swc也可以是swf)的动态加载.即主swf在运行的时候, 可以根据需要动态加载所需的代码模块. 为了讨论方便, 下面所说的代码模块都用swc表示,用 ...

  2. cxf的soap风格+spirng4+maven 客户端

    上篇博客介绍了,cxf的soap风格的服务端,现在我们写客户端来调用 1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...

  3. HTML与XHTML

    HTML:超文本标记语言,基本的网页设计语言 XHTML:基于XML的严格版的HTML XHTML相对于HTML的区别: 标签正确嵌套.标签必须有结束标记.区分大小写.属性值要用双引号.id代替nam ...

  4. 读javascript高级程序设计16-几条函数小技巧

    内容概要 作用域安全的构造函数 惰性载入函数 函数绑定 函数节流 一.作用域安全的构造函数 我们知道,当使用new操作符调用构造函数时,构造函数内部的this会指向新创建对象的实例. function ...

  5. [转]c++类的构造函数详解

    c++构造函数的知识在各种c++教材上已有介绍,不过初学者往往不太注意观察和总结其中各种构造函数的特点和用法,故在此我根据自己的c++编程经验总结了一下c++中各种构造函数的特点,并附上例子,希望对初 ...

  6. spring mvc 注解 学习笔记(一)

    以前接触过spring,但是没有接触spring mvc 以及注解的应用,特习之,记之: 注解了解 @Component 是通用标注, @Controller 标注web控制器, @Service 标 ...

  7. input输入框输入文字出现清空文字按钮

    $("#J_UserName").keyup(function(){ if($("#J_UserName").val() == "" || ...

  8. POJ 2184 01背包+负数处理

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10200   Accepted: 3977 D ...

  9. 【转载】VMware虚拟机修改硬盘容量大小

    很多人在安装虚拟机系统的时候,为了节省硬盘空间,把硬盘容量设置得较小,可是后来发现硬盘容量不够用了.在VMware中又不能直接修改虚拟机的硬盘容量大小,或者重建虚拟机系统,非常麻烦. 其实在VMwar ...

  10. CentOS6.4安装Hadoop2.0.5 alpha - Single Node Cluster

    1.安装JDK7 rpm到/usr/java/jdk1.7.0_40,并建立软链接/usr/java/default到/usr/java/jdk1.7.0_40 [root@server-308 ~] ...