获取mac地址
获取mac地址 ,之前电脑是win7 32的 后来 装了64位的了 为什么会出现异常(:
System.ComponentModel.Win32Exception: 系统找不到指定的文件。(红色异常处))?求解
public string getmacs()
{
string hip = "";
IPHostEntry oiphost = Dns.Resolve(Environment.MachineName);
if (oiphost.AddressList.Length > 0)
hip = oiphost.AddressList[0].ToString();
string dirResults = "";
ProcessStartInfo psi = new ProcessStartInfo();
Process proc = new Process();
psi.FileName = "nbtstat";
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.Arguments = "-a " + hip;
psi.UseShellExecute = false;
proc = Process.Start(psi); //:System.ComponentModel.Win32Exception: 系统找不到指定的文件。
dirResults = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
Match m = Regex.Match(dirResults, "\\w+\\-\\w+\\-\\w+\\-\\w+\\-\\w+\\-\\w\\w");
if (m.ToString() != null)
{
return m.ToString();
}
else
return "";
}
------解决方案--------------------nbtstat这个程序没有找到
------解决方案--------------------http://blog.csdn.net/wqu1205/article/details/5745950
http://www.cnblogs.com/deckard/archive/2009/04/07/1430807.html
http://blog.163.com/yangwenwei2008@126/blog/static/6179273520111016453339/
参考
------解决方案--------------------
using System.Linq;
using System.Net.NetworkInformation;
//忽略回环和隧道(虚拟网卡)
var omitted = NetworkInterfaceType.Loopback
------解决方案--------------------
NetworkInterfaceType.Tunnel;
var mac = NetworkInterface.GetAllNetworkInterfaces().First(ni => (omitted & ni.NetworkInterfaceType) != ni.NetworkInterfaceType).GetPhysicalAddress();
//mac.ToString()