通过Silverlight 4获取MAC地址

发布于 2024-10-19 21:13:46 字数 468 浏览 3 评论 0原文

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

但 3 个条件始终为 false:

if ((Application.Current.IsRunningOutOfBrowser) && 

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

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

i tried doing this-
http://thewayithink.co.uk/post/2010/05/04/Mac-Address-in-Silverlight-4.aspx

but the 3 conditions are always false :

if ((Application.Current.IsRunningOutOfBrowser) && 

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

i guess its because of permissions and security stuff..
is there any way i can get the physical IP address off the client's side?
as i said, i use silverlight 4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风追烟花雨 2024-10-26 21:13:46

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

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

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

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

至于 AutomationFactory 测试 - 这篇文章 上的答案意味着它将当应用程序在具有提升权限的浏览器中运行时为 true。

The security model of Silverlight is such that you can't access anything from the client machine outside the browser sandbox and the (small) amount of disk space allocated to isolated storage. The client machine's MAC address would fall into that category. You can however run your application "Out of Browser" (OOB) with elevated privileges which is what this test is checking for.

The first condition states that you must be running out of browser - so the first question is "Is your application OOB enabled and running out of broswer?".

If not then the test will fail.

Then if the application is running OOB it must also be running with elevated permissions. Is this the case?

As for the AutomationFactory test - the answer on this post implies that it will be true when the application is running out of browser with elevated permissions.

信仰 2024-10-26 21:13:46

使用来自此链接(此处也提到了这个问题)。

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);
        }
    }
}

use this code sample which is from this link (the question is also mentioned here).

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);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文