net实现ping的方法
class ServicePinger
{
private static readonly ILog log = LogManager.GetLogger(typeof(ServicePinger));
public ServicePinger(string siteName, string siteUrl, string serviceUrl)
{
if (siteName == null)
throw new ArgumentException("siteName can't be null"); if (siteUrl == null)
throw new ArgumentException("siteUrl can't be null"); if (serviceUrl == null)
throw new ArgumentException("serviceUrl can't be null"); if (siteName.Length == 0)
throw new ArgumentException("siteName can't be empty"); if (siteUrl.Length == 0)
throw new ArgumentException("siteUrl can't be empty"); if (serviceUrl.Length == 0)
throw new ArgumentException("serviceUrl can't be empty"); pingingSiteName = siteName;
pingingSiteUrl = siteUrl;
serviceUrlToPing = serviceUrl; } private string pingingSiteName = string.Empty;
private string pingingSiteUrl = string.Empty;
private string serviceUrlToPing = string.Empty;
private int timeoutInMilliseconds = 3000; /// <summary>
/// Does the actual pinging of the service
/// </summary>
public void Ping()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUrlToPing);
request.Method = "POST";
request.ContentType = "text/xml";
request.Timeout = timeoutInMilliseconds;
request.Credentials = CredentialCache.DefaultNetworkCredentials; Stream stream = (Stream)request.GetRequestStream();
using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.ASCII))
{
writer.WriteStartDocument();
writer.WriteStartElement("methodCall");
writer.WriteElementString("methodName", "weblogUpdates.ping");
writer.WriteStartElement("params");
writer.WriteStartElement("param");
writer.WriteElementString("value", pingingSiteName);
writer.WriteEndElement();
writer.WriteStartElement("param");
writer.WriteElementString("value", pingingSiteUrl);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
} request.GetResponse();
}
catch (InvalidOperationException ex)
{
log.Error(ex);
}
catch (NotSupportedException ex)
{
log.Error(ex);
} } }
net实现ping的方法的更多相关文章
- Windows 和 Linux 下 禁止ping的方法
Windows 和Linux 下 禁止ping的方法 目的: 禁止网络上的其他主机或服务器ping自己的服务器 运行环境: Windows 03.08 linux 方法: Windows 03下: ...
- Linux禁止ping以及开启ping的方法
---恢复内容开始--- Linux默认是允许Ping响应的,系统是否允许Ping由2个因素决定的:A.内核参数,B.防火墙,需要2个因素同时允许才能允许Ping,2个因素有任意一个禁Ping就无法P ...
- Linux禁止ping和开启ping的方法
Linux默认是允许Ping响应的,系统是否允许Ping由2个因素决定的:A.内核参数,B.防火墙,需要2个因素同时允许才能允许Ping,2个因素有任意一个禁Ping就无法Ping. 一.通过修改 ...
- (转)WIN2003服务器禁PING的方法
方法一:用windows系统自带的防火墙规则设置禁止别人Ping我的机器 win2003系统默认情况下,所有Internet控制消息协议(ICMP)选项均被禁用,也就是对客户机有反应,因而易于受到攻击 ...
- linux静止ping的方法
ping是一个通信协议,是ip协议的一部分,tcp/ip 协议的一部分.利用它可以检查网络是否能够连通,用好它可以很好地帮助我们分析判定网络故障.应用格式为:Ping IP地址.但服务启用ping有时 ...
- 在Windows Server 2008 R2上打开ping的方法
默认安装完Windows Server 2008 R2后,从外面ping服务器的地址是ping不通的,原因是服务器防火墙默认关闭了ICMP的回显请求.需要按照如下方法打开: 在服务器管理器中选择“配置 ...
- CentOS允许/禁止ping的方法
一.临时生效 1.允许ping >/proc/sys/net/ipv4/icmp_echo_ignore_all 2.禁止ping >/proc/sys/net/ipv4/icmp_ech ...
- Android 用ping的方法判断当前网络是否可用
判断网络的情况中,有个比较麻烦的情况就是连上了某个网络,但是那个网络无法上网 ,,, = = 想到了用ping指令来判断,经测试,可行~ ~ ~ private static final boolea ...
- linux禁ping和允许ping的方法
一.系统禁止ping [root@linuxzgf ~]# echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 二.系统允许ping [root@li ...
- mac出现zsh: command not found: ping解决方法
Step1:终端输入以下命令: /sbin/ping 若出现如下信息,说明包含ping命令,是zsh的 PATH有问题,表示没有加载sbin下的命令,需要编辑.zshrc文件. Step2:终端打开. ...
随机推荐
- 百度地图----->地图类型、定位模式、实时交通、我的位置、加入覆盖物、覆盖物详情及提示
在百度地图开发平台 http://developer.baidu.com/map/index.php? title=androidsdk 进行创建应用,获取应用的AK,在进行下载BaiduLBS_An ...
- hdoj--2094--产生冠军(集合函数)
产生冠军 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 编程与算法中的端点问题(linspace(a, b, n),endpoint)
左闭右开,[0, n) ⇒ [0, n-1],共 n 个元素: 1. 列表长与编号 列表(seq,也可以是数组等线性结构)的长度要比末尾元素的编号多 1,比如一个列表内含有 5 个元素,最后一个元素的 ...
- JavaScript中Number常用属性和方法
title: JavaScript中Number常用属性和方法 toc: false date: 2018-10-13 12:31:42 Number.MAX_VALUE--1.79769313486 ...
- POJ 2431 Expedition (priority_queue或者multiset可解)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18655 Accepted: 5405 Descr ...
- A. Amr and Music
解题思路:给出n种乐器学习所需要的时间,以及总共的天数, 问最多能够学多少门乐器,并且输出这几门乐器在原序列中的序号(不唯一) 按照升序排序,为了学到最多的乐器,肯定要选择花费时间最少的来学习 然后用 ...
- swift内存管理
为了解决引用循环的问题. However, with ARC, values are deallocated as soon as their last strong reference is rem ...
- swift语言点评二十一-协议
定义有什么,及哪些必须实现. A protocol defines a blueprint of methods, properties, and other requirements that su ...
- 为什么在3ds Max 按系统默认的快捷键AIT+W 视口最大化切换没反应?
经常使用3ds Max快捷键做效果图可谓是提高作图速度的毕竟之路,做效果图的朋友或许会遇到最大化视口显示失灵的问题,max默认快捷键为Alt+W,这里我不建议大家更改max的默认快捷键,当然Max也提 ...
- 启动tomcat运行maven工程报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:
控制台报错信息: