ASP.Net获取客户端网卡MAC的小例子
程序员文章站
2024-02-29 13:18:40
复制代码 代码如下:using system.text.regularexpressions;using system.diagnostics;public class t...
复制代码 代码如下:
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 "";
}
}
}
}