<configuration>lt;system.web>lt;httphandlers>lt;add verb="post,get" path="ajax/*.ashx"type="ajax.pagehandlerfactory,ajax" />lt;/httphandlers> <system.web>lt;/configuration>
using system;using system.web;namespace ajaxsample{/**//// <summary>/// summary description for methods./// </summary>ublic class demomethods{[ajax.ajaxmethod]ublic string getcustomermac(string clientip) //这里输入客户端ip,这个函数知识测试用,你也可以写一个其他的简单一点的函数代替{ tring mac = "";system.diagnostics.process process =new system.diagnostics.process();rocess.startinfo.filename = "nbtstat";rocess.startinfo.arguments = "-a "+clientip;rocess.startinfo.useshellexecute = false;rocess.startinfo.createnowindow = true;rocess.startinfo.redirectstandardoutput = true;process.start();string output = process.standardoutput.readtoend();int length = output.indexof("mac address = ");if(length>0){mac = output.substring(length+14, 17);}process.waitforexit();return mac.replace("-", "").trim();}}}
function getmac(){var clientip="192.168.0.1";//document.getelementbyid("mac").value=demomethods.getcustomermac(clientip).valuealert(demomethods.getcustomermac(clientip).value);}
lt;script language="javascript"src="default.js"></script>
lt;input type="button"
value="客户端获取ip" >
6.在page页面的page_load事件中加上
private void page_load(object sender, system.eventargs e){// 在此处放置用户代码以初始化页面ajax.utility.registertypeforajax(typeof(ajaxsample.demomethods));}
protected void application_start(object sender, eventargs e){ajax.utility.handlerpath = "ajax";}
新闻热点
疑难解答
图片精选