当前位置: 首页>>代码示例>>C#>>正文


C# NetworkInterface.GetPhysicalAddress方法代码示例

本文整理汇总了C#中System.Net.NetworkInformation.NetworkInterface.GetPhysicalAddress方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkInterface.GetPhysicalAddress方法的具体用法?C# NetworkInterface.GetPhysicalAddress怎么用?C# NetworkInterface.GetPhysicalAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.NetworkInformation.NetworkInterface的用法示例。


在下文中一共展示了NetworkInterface.GetPhysicalAddress方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WrapNetworkInterface

        public WrapNetworkInterface(NetworkInterface ni)
        {
            _networkInterface = ni;

            _physicalAddress = ni.GetPhysicalAddress().ToString();
            _lastRestart = DateTime.Now;

            var search = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE GUID = '" + _networkInterface.Id + "'");
            foreach (ManagementObject mo in search.Get())
                _managementObject = mo;

            _physicalAdapter = false;
            try {
                _physicalAdapter = (bool)_managementObject["PhysicalAdapter"];
            }
            catch {
                // exception if the value doesn't exist, only want True's anyway..
            }
        }
开发者ID:aajm,项目名称:mac,代码行数:19,代码来源:WrapNetworkInterface.cs

示例2: NetInterface

        public NetInterface(NetworkInterface adapterIn)
        {
            // set up the adapter
            adapter = adapterIn;
            stats = adapter.GetIPv4Statistics();

            // set up the logging
            logPath = Path.Combine("logs", Path.Combine(adapter.Description, adapter.GetPhysicalAddress().ToString(), adapter.Id));
            logHandler = new LogHandler(logPath);
            loadDataInstant(DateTime.UtcNow.Ticks);

            // set up the data tracking
            dataTransferStart = currentTicks();
            bytesInSession = stats.BytesReceived;
            bytesOutSession = stats.BytesSent;
            properties = adapter.GetIPProperties();
            //Console.WriteLine(adapter.Name + " " + adapter.Description + " " + adapter.OperationalStatus);

            Tracker = new Tracker(logHandler);
        }
开发者ID:hayfield,项目名称:Bandwidth-Monitor,代码行数:20,代码来源:NetInterface.cs

示例3: GetDeviceInfo

        private string GetDeviceInfo(NetworkInterface adapter)
        {
            if (adapter == null)
            {
                return String.Empty;
            }

            IPInterfaceProperties properties = adapter.GetIPProperties();

            StringBuilder infoBuilder = new StringBuilder();

            infoBuilder.Append(adapter.Description + "\n");
            infoBuilder.Append("=================================================\n");
            infoBuilder.AppendFormat(" ID ......................... : {0}\n",
                adapter.Id);
            infoBuilder.AppendFormat(" Name ....................... : {0}\n",
                adapter.Name);
            infoBuilder.AppendFormat(" Interface type ............. : {0}\n",
                adapter.NetworkInterfaceType);
            infoBuilder.AppendFormat(" Physical Address ........... : {0}\n",
                       BitConverter.ToString(adapter.GetPhysicalAddress().GetAddressBytes()));
            infoBuilder.AppendFormat(" Operational status ......... : {0}\n",
                adapter.OperationalStatus);
            infoBuilder.AppendFormat(" Speed ...................... : {0} Mb/s\n",
                adapter.Speed / 1000000);

            string versions = String.Empty;

            // Create a display string for the supported IP versions.
            if (adapter.Supports(NetworkInterfaceComponent.IPv4))
            {
                versions = "IPv4";
            }
            if (adapter.Supports(NetworkInterfaceComponent.IPv6))
            {
                if (versions.Length > 0)
                {
                    versions += " ";
                }
                versions += "IPv6";
            }

            infoBuilder.AppendFormat(" IP version ................. : {0}\n",
                versions);

            infoBuilder.Append(GetIPAddresses(properties));

            // The following information is not useful for loopback adapters.
            if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
            {
                return infoBuilder.ToString();
            }

            infoBuilder.AppendFormat(" DNS suffix ................. : {0}\n",
                properties.DnsSuffix);

            if (adapter.Supports(NetworkInterfaceComponent.IPv4))
            {
                IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties();

                infoBuilder.AppendFormat(" Index ...................... : {0}\n",
                    ipv4.Index);
                infoBuilder.AppendFormat(" MTU ........................ : {0}\n",
                    ipv4.Mtu);
                infoBuilder.AppendFormat(" APIPA active ............... : {0}\n",
                    ipv4.IsAutomaticPrivateAddressingActive);
                infoBuilder.AppendFormat(" APIPA enabled .............. : {0}\n",
                    ipv4.IsAutomaticPrivateAddressingEnabled);
                infoBuilder.AppendFormat(" DHCP enabled ............... : {0}\n",
                    ipv4.IsDhcpEnabled);
                infoBuilder.AppendFormat(" Forwarding enabled.......... : {0}\n",
                    ipv4.IsForwardingEnabled);
                infoBuilder.AppendFormat(" Uses WINS .................. : {0}\n",
                    ipv4.UsesWins);

                if (ipv4.UsesWins)
                {
                    IPAddressCollection winsServers = properties.WinsServersAddresses;
                    if (winsServers.Count > 0)
                    {
                        foreach (IPAddress winsServer in winsServers)
                        {
                            infoBuilder.AppendFormat(" WINS Server ................ : {0}\n",
                                winsServer);
                        }
                    }
                }
            }

            if (adapter.Supports(NetworkInterfaceComponent.IPv6))
            {
                IPv6InterfaceProperties ipv6 = properties.GetIPv6Properties();

                infoBuilder.AppendFormat(" Index ...................... : {0}\n",
                    ipv6.Index);
                infoBuilder.AppendFormat(" MTU ........................ : {0}\n",
                    ipv6.Mtu);
            }

            infoBuilder.AppendFormat(" DNS enabled ................ : {0}\n",
//.........这里部分代码省略.........
开发者ID:vic-alexiev,项目名称:TrafficDissector,代码行数:101,代码来源:ChooseDeviceForm.cs

示例4: ToString

        static string ToString(NetworkInterface nic)
        {
            return
                "Name=" + nic.Name
                + "; NetworkInterfaceType=" + nic.NetworkInterfaceType.ToString()
                + "; Id=" + nic.Id
                + "; Description=" + nic.Description
                + "; OperationalStatus=" + nic.OperationalStatus.ToString()
                + "; GetPhysicalAddress()=" + nic.GetPhysicalAddress().ToString()
                + "; Speed=" + nic.Speed.ToString()
                + "; SupportsMulticast=" + nic.SupportsMulticast.ToString()
                // + "; LoopbackInterfaceIndex=" + nic.LoopbackInterfaceIndex.ToString()
                + "; IsReceiveOnly=" + nic.IsReceiveOnly.ToString()
                // + "; GetIsNetworkAvailable=" + nic.GetIsNetworkAvailable().ToString()

                ;
        }
开发者ID:renyh1013,项目名称:dp2weixin,代码行数:17,代码来源:SerialCodeForm.cs

示例5: macsMatch

        bool macsMatch(string mac, NetworkInterface nic)
        {
            byte[] macbytes = nic.GetPhysicalAddress().GetAddressBytes();
            if (macbytes.Length != 6) // Looks like an Ethernet mac address
            {
                Debug.Print("Attempting to match non-ethernet physical address");
                return false;
            }

            string macmatchstr = macbytes[0].ToString("x2") + ":" +
                                         macbytes[1].ToString("x2") + ":" +
                                         macbytes[2].ToString("x2") + ":" +
                                         macbytes[3].ToString("x2") + ":" +
                                         macbytes[4].ToString("x2") + ":" +
                                         macbytes[5].ToString("x2");
            Debug.Print("Matching \"" + macmatchstr + "\" and \"" + mac.ToLower() + "\"");

            return (macmatchstr.Equals(mac.ToLower()));
        }
开发者ID:kostaslamda,项目名称:win-xenguestagent,代码行数:19,代码来源:NetInfo.cs

示例6: IfPhysAddress

 /// <summary>
 /// Initializes a new instance of the <see cref="IfPhysAddress"/> class.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="networkInterface">The network interface.</param>
 public IfPhysAddress(int index, NetworkInterface networkInterface)
     : base("1.3.6.1.2.1.2.2.1.6.{0}", index)
 {
     _data = new OctetString(networkInterface.GetPhysicalAddress().GetAddressBytes());
 }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:10,代码来源:IfPhysAddress.cs

示例7: CreateLLDPPacket

        /// <summary>
        /// Generate LLDP packet for adapter
        /// </summary>
        /// <param name="adapter"></param>
        private Packet CreateLLDPPacket(NetworkInterface adapter, PacketInfo pinfo)
        {
            Debug.IndentLevel = 2;

            PhysicalAddress MACAddress = adapter.GetPhysicalAddress();

            IPInterfaceProperties ipProperties = adapter.GetIPProperties();
            IPv4InterfaceProperties ipv4Properties = null; // Ipv4
            IPv6InterfaceProperties ipv6Properties = null;// Ipv6

            // IPv6
            if (adapter.Supports(NetworkInterfaceComponent.IPv6))
            {
                try
                {
                    ipv6Properties = ipProperties.GetIPv6Properties();
                }
                catch (NetworkInformationException e)
                {
                    // Adapter doesn't probably have IPv6 enabled
                    Debug.WriteLine(e.Message, EventLogEntryType.Warning);
                }
            }

            // IPv4
            if (adapter.Supports(NetworkInterfaceComponent.IPv4))
            {
                try
                {
                    ipv4Properties = ipProperties.GetIPv4Properties();
                }
                catch (NetworkInformationException e)
                {
                    // Adapter doesn't probably have IPv4 enabled
                    Debug.WriteLine(e.Message, EventLogEntryType.Warning);
                }
            }

            // System description
            Dictionary<string, string> systemDescription = new Dictionary<string, string>();
            systemDescription.Add("OS", pinfo.OperatingSystem);
            systemDescription.Add("Ver", pinfo.OperatingSystemVersion);
            systemDescription.Add("User", pinfo.Username);
            systemDescription.Add("Uptime", pinfo.Uptime);

            // Port description
            Dictionary<string, string> portDescription = new Dictionary<string, string>();

            // adapter.Description is for example "Intel(R) 82579V Gigabit Network Connection"
            // Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\<number>\Description value
            portDescription.Add("Vendor", adapter.Description);

            /*
             adapter.Id is GUID and can be found in several places:
             In this example it is "{87423023-7191-4C03-A049-B8E7DBB36DA4}"

             Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
             - \NetworkCards\<number>\ServiceName value (in same tree as adapter.Description!)
             - \NetworkList\Nla\Cache\Intranet\<adapter.Id> key
             - \NetworkList\Nla\Cache\Intranet\<domain>\<adapter.Id> key

             Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion
             - \NetworkCards\<number>\ServiceName value

             Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007
               {4D36E972-E325-11CE-BFC1-08002BE10318} == Network and Sharing Center -> viewing adapter's "Properties" and selecting "Device class GUID" from dropdown menu
               {4D36E972-E325-11CE-BFC1-08002BE10318}\0007 == Network and Sharing Center -> viewing adapter's "Properties" and selecting "Driver key" from dropdown menu
             - \NetCfgInstanceId value
             - \Linkage\Export value (part of)
             - \Linkage\FilterList value (part of)
             - \Linkage\RootDevice value

             Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{ad498944-762f-11d0-8dcb-00c04fc3358c}\##?#PCI#VEN_8086&DEV_1503&SUBSYS_849C1043&REV_06#3&11583659&0&C8#{ad498944-762f-11d0-8dcb-00c04fc3358c}\#{87423023-7191-4C03-A049-B8E7DBB36DA4}\SymbolicLink value (part of)
             Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{ 4D36E972 - E325 - 11CE - BFC1 - 08002BE10318}\{ 87423023 - 7191 - 4C03 - A049 - B8E7DBB36DA4}
             Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{ACB3F7A0-2E45-4435-854A-A4E120477E1D}\Connection\Name value (part of)
             Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\{ 87423023 - 7191 - 4C03 - A049 - B8E7DBB36DA4}
             Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iphlpsvc\Parameters\Isatap\{ ACB3F7A0 - 2E45 - 4435 - 854A - A4E120477E1D}\InterfaceName value (part of)

             Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\<various names>\Linkage
             - \Bind value (part of)
             - \Export value (part of)
             - \Route value (part of)

            Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NetBT\Parameters\Interfaces\Tcpip_{87423023-7191-4C03-A049-B8E7DBB36DA4}
            Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Psched\Parameters\NdisAdapters\{87423023-7191-4C03-A049-B8E7DBB36DA4}
            Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\RemoteAccess\Interfaces\<number>\InterfaceName value
            Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Adapters\{87423023-7191-4C03-A049-B8E7DBB36DA4}\IpConfig value (part of)

            IPv4 information:
            Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\{87423023-7191-4C03-A049-B8E7DBB36DA4}

            IPv6 information:
            Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters\Interfaces\{87423023-7191-4c03-a049-b8e7dbb36da4}

            Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\WfpLwf\Parameters\NdisAdapters\{87423023-7191-4C03-A049-B8E7DBB36DA4}

//.........这里部分代码省略.........
开发者ID:raspi,项目名称:WinLLDPService,代码行数:101,代码来源:Base.cs

示例8: IsEthernet

 private static bool IsEthernet(NetworkInterface nic)
 {
     //return nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet;
     if (nic.NetworkInterfaceType != NetworkInterfaceType.Ethernet) return false;
     string key = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
     //        if ((nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
     //|| (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet3Megabit)
     //|| (nic.NetworkInterfaceType == NetworkInterfaceType.FastEthernetFx)
     //|| (nic.NetworkInterfaceType == NetworkInterfaceType.FastEthernetT)
     //|| (nic.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet))
     if (nic.GetPhysicalAddress().ToString().Length != 0)
     {
         string fRegisteryKey = key + nic.Id + "\\Connection";
         Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(fRegisteryKey, false);
         if (rk != null)
         {
             string fPnpInstanceID = rk.GetValue("PnpInstanceID", "").ToString();
             int fMediaSubType = Convert.ToInt32(rk.GetValue("MediaSubType", 0));
             if (fPnpInstanceID.Length > 3 &&
                 fPnpInstanceID.Substring(0, 3) == "PCI")
             {
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:hardborn,项目名称:MonitorManager,代码行数:27,代码来源:SystemHelper.cs

示例9: sNetworkCard

 internal sNetworkCard(NetworkInterface ni)
 {
     _name = ni.Name;
     if (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback)
     {
         _mac = null;
         _isDHCP = false;
         _ipAddress = "127.0.0.1";
         _networkMask = "255.255.255.0";
         _broadcast = "127.0.0.1";
         _live = true;
     }else if (ni.NetworkInterfaceType != NetworkInterfaceType.Tunnel)
     {
         _mac = ni.GetPhysicalAddress().ToString();
         _live = ni.OperationalStatus == OperationalStatus.Up;
         _isDHCP = ni.GetIPProperties().GetIPv4Properties().IsDhcpEnabled;
         if ((_live && _isDHCP) || !_isDHCP)
         {
             foreach (UnicastIPAddressInformation uipa in ni.GetIPProperties().UnicastAddresses)
             {
                 if (uipa.Address.AddressFamily == global::System.Net.Sockets.AddressFamily.InterNetwork)
                 {
                     _ipAddress = uipa.Address.ToString();
                     try
                     {
                         _networkMask = uipa.IPv4Mask.ToString();
                     }catch(Exception e){
                         _networkMask = null;
                     }
                     break;
                 }
             }
             foreach (GatewayIPAddressInformation gipi in ni.GetIPProperties().GatewayAddresses)
             {
                 if (gipi.Address.AddressFamily == global::System.Net.Sockets.AddressFamily.InterNetwork)
                 {
                     _gateway = gipi.Address.ToString();
                     break;
                 }
             }
             _network = null;
             _broadcast = null;
         }
     }
 }
开发者ID:marquismark,项目名称:freeswitchconfig,代码行数:45,代码来源:Structures.cs

示例10: NormalizeMacAddress

 private static string NormalizeMacAddress(NetworkInterface adapter)
 {
     var value = adapter.GetPhysicalAddress().ToString();
     return string.IsNullOrWhiteSpace(value) ? "" : value.Replace(":", "");
 }
开发者ID:jardrake03,项目名称:incert,代码行数:5,代码来源:NetworkUtilities.cs

示例11: sendRawPacket

        /// <summary>
        /// 
        /// </summary>
        /// <param name="adapter"></param>
        /// <param name="payload"></param>
        /// <returns></returns>
        private bool sendRawPacket(NetworkInterface adapter, Packet payload)
        {
            Debug.WriteLine("Sending RAW packet", EventLogEntryType.Information);

            foreach (PcapDevice device in CaptureDeviceList.Instance)
            {
                if (adapter.GetPhysicalAddress().Equals(device.MacAddress))
                {
                    Debug.WriteLine("Device found!", EventLogEntryType.Information);

                    if (!device.Opened)
                    {
                        Debug.WriteLine("Device is not open.", EventLogEntryType.Error);
                        return false;
                    }

                    device.SendPacket(payload);

                    return true;
                }

            }

            return false;
        }
开发者ID:raspi,项目名称:WinLLDPService,代码行数:31,代码来源:Base.cs


注:本文中的System.Net.NetworkInformation.NetworkInterface.GetPhysicalAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。