这篇文章介绍了ASP
Net获取客户端网卡MAC的小例子
有需要的朋友可以参考一下
复制代码 代码如下:
using SystemTextRegularExpressions;
using SystemDiagnostics;
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();
psiFileName = "nbtstat";
psiRedirectStandardInput = false;
psiRedirectStandardOutput = true;
psiArguments = "A " + IP;
psiUseShellExecute = false;
proc = ProcessStart(psi);
dirResults = procStandardOutputReadToEnd();
procWaitForExit();
dirResults=dirResultsReplace(" """)Replace(" """)Replace(" """);
Regex reg=new Regex("Mac[ ]{}Address[ ]{}=[ ]{}(?<key>(()*?)) __MAC"RegexOptionsIgnoreCase|RegexOptionsCompiled);
Match mc=regMatch(dirResults+"__MAC");
if(mcSuccess)
{
return mcGroups["key"]Value;
}
else
{
reg=new Regex("Host not found"RegexOptionsIgnoreCase|RegexOptionsCompiled);
mc=regMatch(dirResults);
if(mcSuccess)
{
return "Host not found!";
}
else
{
return "";
}
}
}
}