复制代码 代码如下:
<asp:ScriptManager runat="server" ScriptMode="Auto" EnablePageMethods="true">
</asp:ScriptManager>
复制代码 代码如下:
function NetPost() {
//创建实例
var wRequest = new Sys.Net.WebRequest();
//设置请求URL
wRequest.set_url("../CheckState/CheckNetState.aspx");
//定义参数
var body = "ip=192.168.1.1";
//设置参数
wRequest.set_body(body);
//设置请求方式
wRequest.set_httpVerb("POST");
//请求完成处理函数
wRequest.add_completed(PostNet);
//执行请求
wRequest.invoke();
}
function PostNet(exector, eventArgs) {
//执行器的状态E :responseAvailable、aborted 或 timedOut。
//仅当 responseAvailable 返回 true 时,事件处理程序才能访问执行器的其他响应信息。
if (exector.get_responseAvailable()) {
//判断状态是否正常
if (exector.get_statusCode() == '200') {
//得到返回值
var returnInfo = exector.get_responseData();
if (returnInfo == "0") {
//显示相关内容
}
}
}
}
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Iaddtech.Environmental.Web.UI.CheckState
{
public partial class CheckNetState : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
//得到参数
string ip = Request.Form["ip"];
int isConnect = PingServer(ip);
//输入返回值
Response.Write(isConnect.ToString());
Response.End();
}
private int PingServer(string ip)
{
System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
options.DontFragment = true;
string data = "t";
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);
int timeout = 1000; // Timeout 时间,单位:毫秒
System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
return 0;
else
return 1;
}
}
}
新闻热点
疑难解答
图片精选