• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# NetworkInformation.NetworkInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



NetworkInterface类属于System.Net.NetworkInformation命名空间,在下文中一共展示了NetworkInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Server

 public Server (string defaultLocation, NetworkInterface networkInterface)
 {
     default_location = defaultLocation;
     network_interface_info = NetworkInterfaceInfo.GetNetworkInterfaceInfo (networkInterface);
     request_listener = new RequestListener (this);
     announcers = new Dictionary<string, Announcer> ();
 }
开发者ID:pacificIT,项目名称:mono-upnp,代码行数:7,代码来源:Server.cs


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


示例3: Client

 public Client (NetworkInterface networkInterface)
 {
     network_interface_info = NetworkInterfaceInfo.GetNetworkInterfaceInfo (networkInterface);
     service_cache = new ServiceCache (this);
     notify_listener = new NotifyListener (this);
     browsers = new Dictionary<string, Browser> ();
 }
开发者ID:pacificIT,项目名称:mono-upnp,代码行数:7,代码来源:Client.cs


示例4: UnicastNetworkAddressInformation

 /// <summary>
 /// Creates a new unicast network address information instance.
 /// </summary>
 /// <param name="iface">The network interface.</param>
 /// <param name="information">The address information.</param>
 public UnicastNetworkAddressInformation(NetworkInterface iface, UnicastIPAddressInformation information)
     : base(iface)
 {
     this.UnicastInformation = information;
     this.Stale = false;
     this.Selected = true;
 }
开发者ID:alexbikfalvi,项目名称:InetAnalytics,代码行数:12,代码来源:UnicastNetworkAddressInformation.cs


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


示例6: Nic

		private Nic(NetworkInterface ni)
		{
			_isInitializing = true;
			Reload(ni);
			_isInitializing = false;
			ConnectivityCheckRequired(this);
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:7,代码来源:Nic.cs


示例7: getSentPackets

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

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


示例8: ChatServer

 public ChatServer(int portNumber, object networkInterface, string serverName)
 {
     this.serverName = serverName;
     this.portNumber = portNumber;
     this.networkInterface = networkInterface as NetworkInterface;
     CreateEventLog();
 }
开发者ID:notdef1ned,项目名称:voice-chat-winrt,代码行数:7,代码来源:ChatServer.cs


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


示例10: NetInterface

 public NetInterface(int id, string name, NetInterfaceType type, NetworkInterface netIface)
 {
     NetshId = id;
     Name = name;
     Type = type;
     networkInterface = netIface;
 }
开发者ID:pjbober,项目名称:NetConfig,代码行数:7,代码来源:NetInterface.cs


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


示例12: NetworkAdapter

        public NetworkAdapter(NetworkInterface networkInterface)
        {
            _networkInterface = networkInterface;

            Thread timer = new Thread(UpdateNetworkInterface);

            timer.IsBackground = true;
            timer.Start();
        }
开发者ID:xoperator,项目名称:GoKapara,代码行数:9,代码来源:NetworkAdapter.cs


示例13: UploadSpeedEvent

 public UploadSpeedEvent(NetworkInterface inter, int sent, int seconds, int comp)
 {
     _Interface = inter;
     _Sent = sent;
     _ToBeFor = seconds;
     _Comparator = comp;
     _LastValue = inter.GetIPv4Statistics().BytesSent;
     _Name = "Upload Speed Usage Event";
 }
开发者ID:CapCalamity,项目名称:ShutdownManager,代码行数:9,代码来源:UploadSpeedEvent.cs


示例14: DownloadSpeedEvent

 public DownloadSpeedEvent(NetworkInterface inter, int received, int seconds, int comp)
 {
     _Interface = inter;
     _Received = received;
     _ToBeFor = seconds;
     _Comparator = comp;
     _LastValue = inter.GetIPv4Statistics().BytesReceived;
     _Name = "Download Speed Usage Event";
 }
开发者ID:CapCalamity,项目名称:ShutdownManager,代码行数:9,代码来源:DownloadSpeedEvent.cs


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


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


示例17: ShowDialog

        /// <summary>
        /// Shows the form as a dialog and the specified network interface.
        /// </summary>
        /// <param name="owner">The owner window.</param>
        /// <param name="iface">The network interface.</param>
        /// <returns>The dialog result.</returns>
        public DialogResult ShowDialog(IWin32Window owner, NetworkInterface iface)
        {
            // If the comment is null, do nothing.
            if (null == iface) return DialogResult.Abort;

            // Set the comment.
            this.control.Interface = iface;

            // Open the dialog.
            return base.ShowDialog(owner);
        }
开发者ID:alexbikfalvi,项目名称:InetAnalytics,代码行数:17,代码来源:FormNetworkInterfaceProperties.cs


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


示例19: AddWirelessProfile

        public static BooleanReason AddWirelessProfile(NetworkInterface adapter, string profile)
        {
            var handle = IntPtr.Zero;
            try
            {
                if (string.IsNullOrWhiteSpace(profile))
                {
                    Log.Warn("Cannot add wireless profile: profile text is empty");
                    return new BooleanReason(false, "Cannot add wireless profile: profile text is empty");
                }

                UInt32 negotiatedVersion;
                UInt32 version = 2;
                if (SystemUtilities.IsWindowsXp())
                    version = 1;

                var result = NativeWifi.WlanOpenHandle(version, IntPtr.Zero, out negotiatedVersion, out handle);
                if (result != 0)
                {
                    Log.WarnFormat("Could not open handle to native wifi interface: {0}", result);
                    return new BooleanReason(false, "Could not open handle to native wifi interface: {0}", result);
                }

                var identifier = new Guid(adapter.Id);
                NativeWifi.WlanReasonCode issueCode;

                result = NativeWifi.WlanSetProfile(
                    handle, identifier, NativeWifi.WlanProfileFlags.AllUser,
                    profile, null, true, IntPtr.Zero, out issueCode);

                if ((result != 0) && (result != 183))
                {
                    var issueText = GetTextForIssue(
                        "An issue occurred while attempting to set a wireless profile: {0}", issueCode);

                    Log.Warn(issueText);
                    return new BooleanReason(false, issueText);
                }

                return new BooleanReason(true, "");
            }

            catch (Exception e)
            {
                Log.Warn(e);
                return new BooleanReason(false, "An exception occurred while setting the wireless profile: {0}", e);
            }
            finally
            {
                if (handle != IntPtr.Zero)
                    NativeWifi.WlanCloseHandle(handle, IntPtr.Zero);
            }
        }
开发者ID:jardrake03,项目名称:incert,代码行数:53,代码来源:NetworkUtilities.cs


示例20: WifiWidget

 public WifiWidget()
 {
     NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
     foreach (NetworkInterface inter in interfaces)
     {
         if (inter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
         {
             _wifi = inter;
             break;
         }
     }
 }
开发者ID:Danielku15,项目名称:WeTabLock,代码行数:12,代码来源:WifiWidget.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NetworkInformation.PhysicalAddress类代码示例发布时间:2022-05-26
下一篇:
C# Mime.ContentType类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap