3

我试过这样做 - http://thewayithink.co.uk/post/2010/05/04/Mac-Address-in-Silverlight-4.aspx

但是这 3 个条件总是错误的:

if ((Application.Current.IsRunningOutOfBrowser) && 

(Application.Current.HasElevatedPermissions) && 
(AutomationFactory.IsAvailable))

我猜是因为权限和安全问题..有什么办法可以让物理IP地址脱离客户端?正如我所说,我使用silverlight 4。

4

2 回答 2

3

Silverlight 的安全模型使得您无法从浏览器沙箱之外的客户端计算机和分配给隔离存储的(少量)磁盘空间访问任何内容。客户端机器的 MAC 地址属于该类别。但是,您可以使用提升的权限运行您的应用程序“浏览器外”(OOB),这是该测试正在检查的内容。

第一个条件表明您必须用尽浏览器 - 所以第一个问题是“您的应用程序 OOB 是否已启用并用尽浏览器?”。

如果不是,那么测试将失败。

然后,如果应用程序正在运行 OOB,它还必须以提升的权限运行。是这样吗?

至于 AutomationFactory 测试 -这篇文章的答案意味着当应用程序用完具有提升权限的浏览器时它将是正确的。

于 2011-03-02T22:23:38.080 回答
0

使用来自此链接的此代码示例(这里也提到了这个问题)。

public partial class MyClient : UserControl
{
    public MyClient()
    {
        MACAddressManager macAddressManager = new MACAddressManager();
        macAddressManager.OnGetMACAddressCompleted += new EventHandler(macAddressManager_OnGetMACAddressCompleted);
        macAddressManager.BeginGetMACAddress();
    }

    void macAddressManager_OnGetMACAddressCompleted(object sender, EventArgs e)
    {
        MACAddressManager manager = (MACAddressManager) sender;
        // MAC Address  value is in manager.MACAddress
    }
  }

  public class MACAddressManager
  {
    private dynamic sWbemServices;
    private dynamic sWbemSink;

    public string MACAddress { get; private set; }
    public event EventHandler OnGetMACAddressCompleted;

    private void EndGetMACAddress(object sender, EventArgs e)
    {
        dynamic objWbemObject = sender;
        MACAddress = objWbemObject.MACAddress;
        if (OnGetMACAddressCompleted != null)
            OnGetMACAddressCompleted(this, EventArgs.Empty);
    }

    public void BeginGetMACAddress()
    {
        if ((Application.Current.IsRunningOutOfBrowser) && (Application.Current.HasElevatedPermissions) && (AutomationFactory.IsAvailable))
        {
            dynamic sWbemLocator = AutomationFactory.CreateObject("WbemScripting.SWBemLocator");
            sWbemServices = sWbemLocator.ConnectServer(".");
            sWbemServices.Security_.ImpersonationLevel = 3; //impersonate

            sWbemSink = AutomationFactory.CreateObject("WbemScripting.SWbemSink");
            sWbemSink.OnObjectReady += new EventHandler(EndGetMACAddress);

            string query = "SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=true";
            sWbemServices.ExecQueryAsync(sWbemSink, query);
        }
    }
}
于 2018-04-23T15:04:20.347 回答