public static string GetCustomerMac()<br /> {<br /> string IP = System.Web.HttpContext.Current.Request.UserHostAddress;<br /> string dirResults = "";<br /> ProcessStartInfo psi = new ProcessStartInfo();<br /> Process proc = new Process();<br /> psi.FileName = "nbtstat";<br /> psi.RedirectStandardInput = false;<br /> psi.RedirectStandardOutput = true;<br /> psi.Arguments = "-A " + IP;<br /> psi.UseShellExecute = false;<br /> proc = Process.Start(psi);<br /> dirResults = proc.StandardOutput.ReadToEnd();<br /> proc.WaitForExit();<br /> dirResults = dirResults.Replace("/r", "").Replace("/n", "").Replace("/t", "");<br /> Regex reg = new Regex("//w{2}-//w{2}-//w{2}-//w{2}-//w{2}-//w{2}", RegexOptions.IgnoreCase | RegexOptions.Compiled);<br /> Match mc = reg.Match(dirResults);<br /> if (mc.Success)<br /> {<br /> return mc.Groups[0].Value;<br /> }<br /> else<br /> {<br /> reg = new Regex("Host not found", RegexOptions.IgnoreCase | RegexOptions.Compiled);<br /> mc = reg.Match(dirResults);<br /> if (mc.Success)<br /> {<br /> return "Host not found!";<br /> }<br /> else<br /> {<br /> return "";<br /> }<br /> }<br /> }
好像只能取同一個路由以內的地址。。