Get MAC Address Through Silverlight 4

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

but three conditions are always false:

if ((Application.Current.IsRunningOutOfBrowser) && 

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

I think this is due to security rights and materials .. is there a way to get the physical IP address from the client? as I said, I use silverlight 4.

+3
source share
2 answers

Silverlight , - , . MAC- . "Out of Browser" (OOB) , .

, , : " OOB broswer?".

, .

, OOB, . ?

AutomationFactory - , , .

+3

, ( ).

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

Source: https://habr.com/ru/post/1795864/


All Articles