C# Ping的例子,可用于测试网络,延迟xx毫秒 C#编写网站测速
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#编写网站测速的更多相关文章
- (转)用C#实现实现简单的 Ping 的功能,用于测试网络是否已经连通
本文转载自:http://blog.csdn.net/xiamin/archive/2009/02/14/3889696.aspx 用C#实现实现简单的 Ping 的功能,用于测试网络是否已经联通 1 ...
- C#实现简单的 Ping 的功能,用于测试网络是否已经联通
/// <summary> /// 是否能 Ping 通指定的主机 /// </summary> /// <param name="ip">ip ...
- linux 测试网络延迟
1.在A服务器上运行qperf &作为服务器节点,由其他服务器来连接测试,默认监听tcp的19765端口.
- 网站测速、ping
1.17ce 2. 360奇云测 3.http://ping.chinaz.com/ 效果图:
- JS 测试网络速度与网络延迟
一.延迟与网速 通过js加载一张1x1的极小图片,测试出图片加载的所用的时长.如果换一个几百KB的图片,则可心用来计算下载网速 document.write('<input type=" ...
- 网络延迟查看器 Network latency view 1.4
这是个用于查看网络延迟/ip/主机/地区的工具,内外网通吃,外网可通过这里下载csv以显示国家(地区) 可以自己决定winpcap或者原始套接字进行捕捉 如果只扫描内网推荐angryip 这是款发布在 ...
- Android IOS WebRTC 音视频开发总结(五六)-- 如何测试网络性能?
本文主要介绍如何测试网络性能,文章来自博客园RTC.Blacker,欢迎关注微信公众号blacker,更多详见www.rtc.help 网络性能直接决定了视频通话效果,比如qq,很多时候我们我们觉得通 ...
- 超级 Ping 监测工具——为您的网络状态保驾护航
关于 Ping Ping 是一个网络命令,主要是用于确定本地主机是否能与另一台主机交换(发送与接收)数据.根据返回的信息,就可以推断 TCP/IP 参数是否设置得正确以及运行是否正常.正常情况下,Pi ...
- linux ping IP地址与telnet 测试IP端口
ping命令是不能够测试端口的,ping只是测试网络联接状况以及信息包发送和接收状况. 格式:ping IP地址或主机名 [-t] [-a] [-n count] [-l size] 参数含义:-t不 ...
随机推荐
- (转载) PowerDesigner 生成sql文件
Powerdesigner15-物理模型-导出建表sql语句 博客分类: Powerdesigner Powerdesigner15-物理模型-导出建表sql语句 1.设置哪种数据库导出的sql语句, ...
- linux下多路复用模型之Select模型
Linux关于并发网络分为Apache模型(Process per Connection (进程连接) ) 和TPC , 还有select模型,以及poll模型(一般是Epoll模型) Select模 ...
- codeforces 725D . Contest Balloons(贪心+优先队列)
题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...
- Stack的pop和push操作
#include <stack> #include <cstdio> using namespace std; int main(){ stack<int> s; ...
- 读javascript高级程序设计04-canvas
一.基本用法 1.要使用canvas元素,需要先给定其width和height来设置绘图区域的大小.canvas中间的文本会在浏览器不支持canvas的情况下显示出来. <canvas widt ...
- public,protected,private辨析
一直没有很清楚理解这三个修饰权限的区别,今天终于搞明白了,现总结如下: private:最严格的一个,子类无法继承,只有本类内部内访问,在其余类及子类中通过 "类名.方法" 去调用 ...
- jQuery实现加入购物车飞入动画效果
<script src="jquery.js"></script> <script src="jquery.fly.min.js" ...
- HDU 1253 胜利大逃亡
Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C ...
- Struts2+Hibernate+Spring 整合示例[转]
原文 http://blog.csdn.net/tkd03072010/article/details/7468769 Spring整合Struts2.Hibernate原理概述: 从用户角度来看,用 ...
- Scala HelloWorld
1) 使用MVN创建项目 mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtif ...