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


C# NetworkInterface.GetIPProperties方法代码示例

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


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

示例1: 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

示例2: IfMtu

 /// <summary>
 /// Initializes a new instance of the <see cref="IfMtu"/> class.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="networkInterface">The network interface.</param>
 public IfMtu(int index, NetworkInterface networkInterface)
     : base("1.3.6.1.2.1.2.2.1.4.{0}", index)
 {
     if (networkInterface.Supports(NetworkInterfaceComponent.IPv4))
     {
         var pv4InterfaceProperties = networkInterface.GetIPProperties().GetIPv4Properties();
         _data = new Integer32(pv4InterfaceProperties == null ? -1 : pv4InterfaceProperties.Mtu);
     }
     else
     {
         _data = new Integer32(networkInterface.GetIPProperties().GetIPv6Properties().Mtu);
     }
 }
开发者ID:nickolaykon,项目名称:sharpsnmplib,代码行数:18,代码来源:IfMtu.cs

示例3: NetworkInterface

 internal NetworkInterface(NetworkInterfaceInformation info)
 {
     Information = info;
     IPv4Index = -1;
     IPv6Index = -1;
     if (info.Supports(NetworkInterfaceComponent.IPv4))
     {
         IPv4Index = info.GetIPProperties().GetIPv4Properties().Index;
     }
     if (info.Supports(NetworkInterfaceComponent.IPv6))
     {
         IPv6Index = info.GetIPProperties().GetIPv6Properties().Index;
     }
     Index = Interlocked.Increment(ref NextIndex);
 }
开发者ID:bbc,项目名称:sdp-test,代码行数:15,代码来源:NetworkInterface.cs

示例4: GetNetworkInterfaceInfo

 public static NetworkInterfaceInfo GetNetworkInterfaceInfo (NetworkInterface networkInterface)
 {
     if (networkInterface == null) {
         return new NetworkInterfaceInfo (IPAddress.Any, 0);
     }
     var properties = networkInterface.GetIPProperties ();
     var ipv4_properties = properties.GetIPv4Properties ();
     if (ipv4_properties == null) {
         throw new ArgumentException ("The specified network interface does not support IPv4.", "networkInterface");
     }
     var host_name = Dns.GetHostName ();
     foreach (var address in properties.UnicastAddresses)
     {
         string addressHostname = null;
         try
         {
             addressHostname = Dns.GetHostEntry(address.Address).HostName;
         }
         catch(SocketException)
         {
             
         }
         if (address.Address.AddressFamily == AddressFamily.InterNetwork && addressHostname == host_name) {
             return new NetworkInterfaceInfo (address.Address, ipv4_properties.Index);
         }
     }
     throw new ArgumentException (string.Format (
         "The specified network interface does not have a suitable address for the local hostname: {0}.", host_name), "networkInterface");
 }
开发者ID:automaters,项目名称:Mono.Upnp,代码行数:29,代码来源:NetworkInterfaceInfo.cs

示例5: getSentPackets

        public long getSentPackets( NetworkInterface conn )
        {
            IPInterfaceProperties properties = conn.GetIPProperties();
              IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();

             return ipstat.BytesSent;
        }
开发者ID:kpelikhovsky,项目名称:TrafficLogger,代码行数:7,代码来源:StatCollector.cs

示例6: getReceivedTraffic

        /*
           * Get received traffic
           * returns String[] array
          */
        public long getReceivedTraffic( NetworkInterface conn )
        {
            IPInterfaceProperties properties = conn.GetIPProperties();
             IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();

             return ipstat.BytesReceived;
        }
开发者ID:kpelikhovsky,项目名称:TrafficLogger,代码行数:11,代码来源:StatCollector.cs

示例7: GetUpdateType

        public static UpdateType GetUpdateType(NetworkInterface oldInterface, NetworkInterface newInterface)
        {
            if (oldInterface.Id != newInterface.Id)
                return UpdateType.Name;

            IPInterfaceProperties oldIPProps = oldInterface.GetIPProperties();
            IPInterfaceProperties newIPProps = newInterface.GetIPProperties();

            if (HasIPChanged(oldIPProps, newIPProps))
                return UpdateType.IP;

            if (HasNetmaskChanged(oldIPProps, newIPProps))
                return UpdateType.Netmask;

            if (HasGatewayChanged(oldIPProps, newIPProps))
                return UpdateType.Gateway;

            if (HasDHCPChanged(oldIPProps, newIPProps))
                return UpdateType.DHCP;

            if (HasDNSChanged(oldIPProps, newIPProps))
                return UpdateType.DNS;

            if (!oldIPProps.Equals(newIPProps))
                return UpdateType.Other;

            return UpdateType.None;
        }
开发者ID:pjbober,项目名称:NetConfig,代码行数:28,代码来源:NetworkInterfaceComparer.cs

示例8: GetGatewayAddressFromNetInterface

 public static IPAddress GetGatewayAddressFromNetInterface(NetworkInterface intf)
 {
     IPInterfaceProperties ipProps = intf.GetIPProperties();
     if (ipProps == null)
         return IPAddress.Any;
     if (ipProps.GatewayAddresses == null || ipProps.GatewayAddresses.Count == 0)
         return IPAddress.Any;
     return ipProps.GatewayAddresses[0].Address;
 }
开发者ID:JoeGilkey,项目名称:RadioLog,代码行数:9,代码来源:NetworkUtils.cs

示例9: isNetworkConnected

        public Boolean isNetworkConnected(NetworkInterface net)
        {
            Boolean bReturn = false;
            if (net != null && net.OperationalStatus == OperationalStatus.Up && net.GetIPProperties() != null && net.Description != null && net.NetworkInterfaceType != NetworkInterfaceType.Loopback) {
                bReturn =  true;
            }

            Helper.doLog("isNetworkConnected " + net.Id + " = " + bReturn, Properties.Settings.Default.DebugMode);

            return bReturn;
        }
开发者ID:halfmonty,项目名称:VPNWatcher,代码行数:11,代码来源:InterfaceHandler.cs

示例10: SetSocketOptionsForNic

		private void SetSocketOptionsForNic(NetworkInterface nic)
		{
			nic.GetIPProperties()
				.UnicastAddresses
				.Where(unicast => unicast.Address.AddressFamily == AddressFamily.InterNetwork)
				.ToList()
				.ForEach(
					address =>
					socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
					                       new MulticastOption(IPAddress.Parse(AllHostsMulticastIP), address.Address)));
		}
开发者ID:BlueBlock,项目名称:rhino-licensing,代码行数:11,代码来源:DiscoveryHost.cs

示例11: NetworkConfigModel

 public NetworkConfigModel(NetworkInterface ni)
 {
     var ip = ni.GetIPProperties();
     this.IpAddress = ip.UnicastAddresses.Count > 0 ? ip.UnicastAddresses[0].Address.ToString() : "";
     this.Gateway = ip.GatewayAddresses.Count > 0 ? ip.GatewayAddresses[0].Address.ToString() : "";
     this.Subnet = ip.UnicastAddresses.Count > 0 ? ip.UnicastAddresses[0].IPv4Mask.ToString() : "";
     this.DNSList = ip.DnsAddresses.Count > 0 ? string.Join(";", ip.DnsAddresses.Select(dn => dn.ToString())) : "";
     this.NetworkName = ni.Name;
     this.InterfaceName = ni.Description;
     this.UseDHCP = string.IsNullOrEmpty(this.IpAddress) && string.IsNullOrEmpty(this.Gateway);
 }
开发者ID:ozgend,项目名称:hive,代码行数:11,代码来源:NetworkConfigModel.cs

示例12: AddRoute

        /// <summary>
        /// Returns the destination IP we'll later want to delete
        /// </summary>
        /// <param name="adapter"></param>
        /// <param name="hostOrIp"></param>
        /// <returns></returns>
        public static string AddRoute(NetworkInterface adapter, string hostOrIp )
        {
            IPAddress remoteAddress = null;
            if (IPAddress.TryParse(hostOrIp, out remoteAddress)) {
                // already an IP address
            } else {
                // resolve it
                try
                {
                    IPAddress[] addresslist = Dns.GetHostAddresses(hostOrIp);
                    if (addresslist.Length == 0)
                    {
                        MessageBox.Show("Can't resolve " + hostOrIp);
                    }
                    else
                    {
                        remoteAddress = addresslist[0];
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                    return null;
                }

            }

            IPInterfaceProperties properties = adapter.GetIPProperties();

            try
            {
                if (remoteAddress != null)
                {
                    GatewayIPAddressInformationCollection gateways = properties.GatewayAddresses;
                        for (int j = 0; j < gateways.Count; j++)
                        {
                            GatewayIPAddressInformation gateway = gateways[j];

                            // Add the route entry to the route table to solve the Windows XP issue.
                            AddRoute(gateway.Address.ToString(), remoteAddress.ToString());
                        }
                }
            }

            catch (Exception ex)
            {
                //DebugEx.WriteException(ex);
                MessageBox.Show(ex.Message, "Error");
                return null;
            }

            return remoteAddress.ToString();
        }
开发者ID:ccampo133,项目名称:PlotPing,代码行数:59,代码来源:NetworkInterfaceUtils.cs

示例13: GetIpv4StringFromNetworkAdapter

 private static string GetIpv4StringFromNetworkAdapter(string result, NetworkInterface adapter)
 {
     if (adapter == null) return null;
     foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses)
     {
         if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
         {
             result = ip.Address.ToString();
         }
     }
     return result;
 }
开发者ID:Stefanying,项目名称:CenterControlEditor,代码行数:12,代码来源:NetLib.cs

示例14: GetGatewayAddress

        public static IPAddress GetGatewayAddress(NetworkInterface iface)
        {
            if (iface == null)
                return IPAddress.Parse(BadIP);

            IPInterfaceProperties ipProperties = iface.GetIPProperties();

            foreach (GatewayIPAddressInformation ip in ipProperties.GatewayAddresses)
                if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
                    return ip.Address;

            return IPAddress.Parse(BadIP);
        }
开发者ID:pjbober,项目名称:NetConfig,代码行数:13,代码来源:Helpers.cs

示例15: GetDNSAddress

        public static IPAddress GetDNSAddress(NetworkInterface iface)
        {
            if (iface == null)
                return IPAddress.Parse(BadIP);

            IPInterfaceProperties ipProperties = iface.GetIPProperties();

            foreach (IPAddress ip in ipProperties.DnsAddresses)
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                    return ip;

            return IPAddress.Parse(BadIP);
        }
开发者ID:pjbober,项目名称:NetConfig,代码行数:13,代码来源:Helpers.cs


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