Пример #1
1
        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);
        }
Пример #2
0
        long get_session_ip()
        {
            long session = 0;

            session = IfaceEthernet.GetIPv4Statistics().BytesReceived;
            return(session);
        }
Пример #3
0
        public long getSentPackets( NetworkInterface conn )
        {
            IPInterfaceProperties properties = conn.GetIPProperties();
              IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();

             return ipstat.BytesSent;
        }
Пример #4
0
        /*
           * Get received traffic
           * returns String[] array
          */
        public long getReceivedTraffic( NetworkInterface conn )
        {
            IPInterfaceProperties properties = conn.GetIPProperties();
             IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();

             return ipstat.BytesReceived;
        }
 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";
 }
 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";
 }
Пример #7
0
        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;
        }
        private void UpdateNetworkInterface()
        {
            System.Net.NetworkInformation.NetworkInterface nic = nicArr[0];
            IPv4InterfaceStatistics interfaceStats             = nic.GetIPv4Statistics();
            int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived - lblBytesReceived);

            lblBytesReceived = interfaceStats.BytesReceived;
            MainForm.updateDownloadSpeed(bytesReceivedSpeed);
            MainForm.updateEstimatedTime();
        }
        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;
        }
        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();
        }
Пример #11
0
        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);
              }
        }
        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();
                    }
                }
        }