首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

获取mac地址解决思路

2013-03-01 
获取mac地址获取mac地址,之前电脑是win7 32的 后来 装了64位的了 为什么会出现异常(:System.ComponentMode

获取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()

热点排行