更改Citrix中的MAC地址 [英] Changing MAC Address in Citrix

查看:123
本文介绍了更改Citrix中的MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个热门的办公桌上工作,其中MAC id不是静态的。 MAC地址每天都在变化。

我正在研究一个必须存储并将数据映射到MAC ID的.NET应用程序。但是,随着MAC地址的变化,数据无法映射。是否有任何类似于MAC地址的属性可供.NET在Citrix环境中用于映射到hotdesk?

I am working on a .NET Application that has to be store and map data to a MAC id. However, as the MAC address changes, data cannot be mapped. Is there any property similar to MAC address that can be used by .NET in Citrix environment to map to a hotdesk?

任何帮助将不胜感激。

Any help in this regard will be appreciated.

推荐答案

您好,

请在发布前考虑您要发布的论坛。

Please consider which forum you're going to post in before posting.

这是你的问题的错误论坛,因为它与WPF无关。

This is the wrong forum for your question because it's got nothing to do with WPF.

如果我理解正确,可以获得MAC C#中的地址将解决您的问题。 

If I understand you correctly, get MAC address in C# will resolve your issue. 

有几种方法可以在C#中读取MAC地址:

1。通过IPConfig获取MAC地址

1. get the MAC address by the IPConfig

publicstatic List<string> GetMacByIPConfig()
{
  List<string> macs =new List<string>();
  ProcessStartInfo startInfo = new ProcessStartInfo("ipconfig", "/all");
  startInfo.UseShellExecute = false;
  startInfo.RedirectStandardInput = true;
  startInfo.RedirectStandardOutput = true;
  startInfo.RedirectStandardError = true;
  startInfo.CreateNoWindow = true;
  Process p = Process.Start(startInfo);
  //intercept the output stream
  StreamReader reader = p.StandardOutput;
  string line = reader.ReadLine();

  while (!reader.EndOfStream)
  {
    if (!string.IsNullOrEmpty(line))
    {
      line = line.Trim();
      if (line.StartsWith("Physical Address"))
      {
        macs.Add(line);
      }
    }
    line = reader.ReadLine();
  }
  p.WaitForExit();
  p.Close();
  reader.Close();
 
  return macs;
}

2.通过WMI获取MAC地址,注意t 方法依赖于WMI的系统服务,这些服务通常不会关闭;但是,如果系统服务丢失或有问题,该方法不能
获取MAC地址。

2.get the MAC address by the WMI, Note the method relies on WMI's system services, which are generally not shut down; however, if the system services are missing or have problems, the method can not obtain the MAC address.

publicstatic List<string> GetMacByWMI()
{
  List<string> macs =new List<string>();
  try
  {
    string mac ="";
    ManagementClass mc =new ManagementClass("Win32_NetworkAdapterConfiguration");
    ManagementObjectCollection moc = mc.GetInstances();
    foreach (ManagementObject mo in moc)
    {
      if ((bool)mo["IPEnabled"])
      {
        mac = mo["MacAddress"].ToString();
        macs.Add(mac);
      }
    }
    moc =null;
    mc =null;
  }
  catch
  {
  }

  return macs;
}

3.通过NetworkInterface获取MAC地址。

3.get the MAC address by the NetworkInterface.

1)如果当前网卡被禁用(硬件处于硬关机状态),则网卡的MAC地址不可用(您可以禁用网卡) 。

2)如果当前启用了多个NIC,则第一个返回的地址是最近启用的网络连接的信息

1) If the current network card is disabled (hardware is in a hard-off state), the MAC address of the network card is not available (you can disable the network card).
2) If multiple NICs are currently enabled, the first returned address is the information of the most recently enabled network connection

publicstatic NetworkInterface[] NetCardInfo()
{
  return NetworkInterface.GetAllNetworkInterfaces();
}


publicstatic List<string> GetMacByNetworkInterface()
{
  List<string> macs =new List<string>();
  NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
  foreach (NetworkInterface ni in interfaces)
  {
    macs.Add(ni.GetPhysicalAddress().ToString());
  }
  return macs;
}

4。通过SendARP获取MAC地址

4. get the MAC address by the SendARP

当网络被禁用或是未连接到网络(如果未插入网络电缆)

publicstaticstring GetMacBySendARP(string remoteIP)
{
  StringBuilder macAddress =new StringBuilder();

  try
  {
    Int32 remote = inet_addr(remoteIP);

    Int64 macInfo =new Int64();
    Int32 length =6;
    SendARP(remote, 0, ref macInfo, ref length);

    string temp = Convert.ToString(macInfo, 16).PadLeft(12, '0').ToUpper();

    int x =12;
    for (int i =0; i <6; i++)
    {
      if (i ==5)
      {
        macAddress.Append(temp.Substring(x -2, 2));
      }
      else
      {
        macAddress.Append(temp.Substring(x -2, 2) +"-");
      }
      x -=2;
    }

    return macAddress.ToString();
  }
  catch
  {
    return macAddress.ToString();
  }
}

[DllImport("Iphlpapi.dll")]
privatestaticexternint SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
[DllImport("Ws2_32.dll")]
privatestaticextern Int32 inet_addr(string ip);

此致,

Bob


这篇关于更改Citrix中的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆