ASP.Net获取客户端网卡MAC的小例子
代码如下:
using System.Text.RegularExpressions; using System.Diagnostics; public class test { public test {} public static string GetCustomerMac(string IP) //para IP is the clients IP { string dirResults=""; ProcessStartInfo psi = new ProcessStartInfo(); Process proc = new Process(); psi.FileName = "nbtstat"; psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.Arguments = "-A " + IP; psi.UseShellExecute = false; proc = Process.Start(psi); dirResults = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); dirResults=dirResults.Replace(" ","").Replace(" ","").Replace(" ",""); Regex reg=new Regex("Mac[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)*?)) __MAC",RegexOptions.IgnoreCase|RegexOptions.Compiled); Match mc=reg.Match(dirResults+"__MAC"); if(mc.Success) { return mc.Groups["key"].Value; } else { reg=new Regex("Host not found",RegexOptions.IgnoreCase|RegexOptions.Compiled); mc=reg.Match(dirResults); if(mc.Success) { return "Host not found!"; } else { return ""; } } } }
相关推荐
Micusd 2020-11-19
cheidou 2020-11-19
星马殇 2020-11-18
Echodat 2020-10-08
flyToSkyL 2020-09-11
zjc 2020-09-03
阳光普照 2020-09-01
十年砍柴 2020-08-30
猪猪侠喜欢躲猫猫 2020-08-17
ladewang 2020-08-17
渣渣灰 2020-08-13
blankt 2020-08-15
vickay 2020-08-09
TinyDolphin 2020-08-09
山兔与孟婆 2020-08-09
longjing 2020-08-07
xiaogoua 2020-08-06