1. 新建一个项目,在引用中添加引用Ajax.dll,Ajax.dll位于下载的压缩包里面。
2.建立HttpHandler,在web.config里面加上
< @H_403_4@configuration> < @H_403_4@system.web> < httpHandlers> < add verb="POST,GET" @H_403_4@path="ajax/*.ashx" type="Ajax.PageHandlerFactory,Ajax" /> < /httpHandlers> < system.web> < /configuration> |
using System; using System.Web; @H_403_4@namespace AjaxSample { /**//// < summary> /// Summary description for Methods. /// < /summary> public @H_403_4@class DemoMethods { [Ajax.AjaxMethod] public @H_403_4@string GetCustomerMac(string clientIP) //这里输入客户端IP,这个函数知识测试用,你也可以写一个其他的简单一点的函数代替 { string mac = ""; System.Diagnostics.@H_403_4@Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "nbtstat"; process.StartInfo.Arguments = "-a "+clientIP; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); string output = process.StandardOutput.ReadToEnd(); @H_403_4@int length = output.IndexOf("MAC @H_403_4@Address = "); if(length>0) { mac = output.Substring(length+14,17); } process.WaitForExit(); return mac.Replace("-","").Trim(); } } } |