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


C# NetworkInterface.GetIPv4Statistics方法代码示例

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


在下文中一共展示了NetworkInterface.GetIPv4Statistics方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getSentPackets

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

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

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

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

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

示例6: NetworkMonitorWidget

        public NetworkMonitorWidget(int interfaceId = 0, int updateTime = 1000,
		Color? backgroundColor = null, Color? foregroundColor = null)
        {
            this.backgroundColor = backgroundColor ?? Color.White;
            this.foregroundColor = foregroundColor ?? Color.Black;

            if (!NetworkInterface.GetIsNetworkAvailable())
            {
            return;
            }

            updateDuration = updateTime;
            updateTimer = new Timer { Interval = updateTime };
            updateTimer.Tick += OnTimerTick;

            networkInterface = NetworkInterface.GetAllNetworkInterfaces()[interfaceId];
            oldReceived = networkInterface.GetIPv4Statistics().BytesReceived;
            oldSent = networkInterface.GetIPv4Statistics().BytesSent;
        }
开发者ID:nikku,项目名称:dawsome,代码行数:19,代码来源:NetworkMonitorWidget.cs

示例7: ProvidesInternetAccess

        static bool ProvidesInternetAccess(NetworkInterface face)
        {
            if ((face.OperationalStatus != OperationalStatus.Up) ||
                (face.NetworkInterfaceType == NetworkInterfaceType.Tunnel) ||
                (face.NetworkInterfaceType == NetworkInterfaceType.Loopback))
            {
                return false;
            }

            var statistics = face.GetIPv4Statistics();
            if ((statistics.BytesReceived > 0) && (statistics.BytesSent > 0))
            {
                return true;
            }
            return false;
        }
开发者ID:gitter-badger,项目名称:Shapeshifter,代码行数:16,代码来源:EnvironmentInformation.cs

示例8: GetDeviceIPv4Statistics

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

            IPv4InterfaceStatistics ipv4Stat = adapter.GetIPv4Statistics();

            StringBuilder ipv4StatBuilder = new StringBuilder();

            ipv4StatBuilder.Append("IPv4 Statistics\n");
            ipv4StatBuilder.Append("=================================================\n");

            ipv4StatBuilder.AppendFormat(" Bytes received .................. : {0}\n",
                ipv4Stat.BytesReceived);
            ipv4StatBuilder.AppendFormat(" Unicast packets received ........ : {0}\n",
                ipv4Stat.UnicastPacketsReceived);
            ipv4StatBuilder.AppendFormat(" Non-Unicast packets received .... : {0}\n",
                ipv4Stat.NonUnicastPacketsReceived);
            ipv4StatBuilder.AppendFormat(" Incoming packets discarded ...... : {0}\n",
                ipv4Stat.IncomingPacketsDiscarded);
            ipv4StatBuilder.AppendFormat(" Incoming packets with errors .... : {0}\n",
                ipv4Stat.IncomingPacketsWithErrors);
            ipv4StatBuilder.AppendFormat(" Bytes sent ...................... : {0}\n",
                ipv4Stat.BytesSent);
            ipv4StatBuilder.AppendFormat(" Unicast packets sent ............ : {0}\n",
                ipv4Stat.UnicastPacketsSent);
            ipv4StatBuilder.AppendFormat(" Non-Unicast packets sent ........ : {0}\n",
                ipv4Stat.NonUnicastPacketsSent);
            ipv4StatBuilder.AppendFormat(" Outgoing packets discarded ...... : {0}\n",
                ipv4Stat.OutgoingPacketsDiscarded);
            ipv4StatBuilder.AppendFormat(" Outgoing packets with errors .... : {0}\n",
                ipv4Stat.OutgoingPacketsWithErrors);
            ipv4StatBuilder.AppendFormat(" Incoming unknown protocol packets : {0}\n",
                ipv4Stat.IncomingUnknownProtocolPackets);
            ipv4StatBuilder.AppendFormat(" Output queue length ............. : {0}\n",
                ipv4Stat.OutputQueueLength);

            return ipv4StatBuilder.ToString();
        }
开发者ID:vic-alexiev,项目名称:TrafficDissector,代码行数:41,代码来源:ChooseDeviceForm.cs

示例9: MonitorInterface

        private void MonitorInterface(NetworkInterface networkInterface, int pollingIntervalSec, 
      DoWorkEventArgs e)
        {
            long totalBytesReceived = 0;
              long totalBytesSent = 0;
              long prevTotalBytesReceived = 0;
              long prevTotalBytesSent = 0;

              while (true)
              {
            if (worker.CancellationPending)
            {
              e.Cancel = true;
              break;
            }

            prevTotalBytesReceived = totalBytesReceived;
            prevTotalBytesSent = totalBytesSent;

            //totalBytesReceived = networkInterface.GetIPv4Statistics().BytesReceived;
            m_bandwidthInfo.TotalBytesReceived = networkInterface.GetIPv4Statistics().BytesReceived;
            //totalBytesSent = networkInterface.GetIPv4Statistics().BytesSent;
            m_bandwidthInfo.TotalBytesSent = networkInterface.GetIPv4Statistics().BytesSent;

            long bytesReceived = totalBytesReceived - prevTotalBytesReceived;
            double kBytesReceived = bytesReceived / 1024;

            long bytesSent = totalBytesSent - prevTotalBytesSent;
            double kBytesSent = bytesSent / 1024;

            LOG.Info("Bytes Received: {0}. Total Bytes Received: {1}", bytesReceived,
              m_bandwidthInfo.TotalBytesReceived);
            LOG.Info("Bytes Sent: {0}.  Total Bytes Sent: {1}", bytesSent,
              m_bandwidthInfo.TotalBytesSent);

            worker.ReportProgress(100, m_bandwidthInfo);

            Thread.Sleep(pollingIntervalSec * 1000);
              }
        }
开发者ID:dlang89,项目名称:BandwidthMonitor,代码行数:40,代码来源:BandwidthMonitor.cs

示例10: AddInterface

        public void AddInterface(NetworkInterface adapter)
        {
            if (adapter.NetworkInterfaceType == NetworkInterfaceType.Tunnel || adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
                return;
            if (adapter.OperationalStatus == OperationalStatus.Down)
                return;

                bool found = false;
                foreach (var s in _interfaces){
                    if (s.name == adapter.Name)
                    {
                        found = true;
                    }
                }
                if(found == false){
                    var inf = new StatNetworkItem(adapter.Name);
                     _interfaces.Add(inf);
                    sessionID = DateTime.Now.Ticks;
                }

                foreach (var s in _interfaces){
                    if(s.name == adapter.Name){
                        if (resetAddresses)
                        {
                            s.address = null;
                            IPInterfaceProperties properties = adapter.GetIPProperties();
                            UnicastIPAddressInformationCollection uniCast = properties.UnicastAddresses;
                            foreach (UnicastIPAddressInformation uni in uniCast)
                            {
                                var address = uni.Address.ToString();
                                if (address.Contains("127."))
                                    continue;

                                Match match = Regex.Match(address, @"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", RegexOptions.IgnoreCase);
                                if (match.Success)
                                {
                                    s.address = address;
                                }
                            }
                        }

                         var ns = new NetworkStatQueue
                         {
                             Upload = adapter.GetIPv4Statistics().BytesSent,
                             Download = adapter.GetIPv4Statistics().BytesReceived,
                             SampleID = historyIndex
                         };
                        s.historyTotals.Enqueue(ns);
                        s.UpdateBandwidth();
                    }
                }
        }
开发者ID:Balamir,项目名称:iStat-Server-for-Windows,代码行数:52,代码来源:StatNetwork.cs


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