使用C#ping IP地址 [英] Ping a IP address using C#
本文介绍了使用C#ping IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在asp.net页面中使用按钮点击事件ping一个IP地址,如果ping成功,则重定向到该IP地址(一个URL)
IP地址示例:http://xxx.xxx.xxx.xx/sample
解决方案
http://forums.asp.net/t/1597694.aspx [ ^ ]
按状态获取ping结果
请参阅下面的代码
protected void btnSubmit_Click(object sender,EventArgs e)
{
Ping ping = new Ping();
PingReply pingresult = ping.Send(81.2.199.57);
if(pingresult.Status.ToString()==Success)
{
Response.Redirect(http://xxx.xxx.xxx.xx/sample);
}
}
http://stackoverflow.com/questions/11800958/using-ping-in-c-sharp
I want to ping a IP address with button click event in asp.net page and if ping is successful then redirect to that IP address(of a URL)
Example of IP address: http://xxx.xxx.xxx.xx/sample
解决方案
http://forums.asp.net/t/1597694.aspx[^]
Get ping result by it's status
See the codes are following below
protected void btnSubmit_Click(object sender, EventArgs e) { Ping ping = new Ping(); PingReply pingresult = ping.Send("81.2.199.57"); if (pingresult.Status.ToString() == "Success") { Response.Redirect("http://xxx.xxx.xxx.xx/sample"); } }
http://stackoverflow.com/questions/11800958/using-ping-in-c-sharp
这篇关于使用C#ping IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文