本文整理汇总了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);
}
示例2: getSentPackets
public long getSentPackets( NetworkInterface conn )
{
IPInterfaceProperties properties = conn.GetIPProperties();
IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();
return ipstat.BytesSent;
}
示例3: getReceivedTraffic
/*
* Get received traffic
* returns String[] array
*/
public long getReceivedTraffic( NetworkInterface conn )
{
IPInterfaceProperties properties = conn.GetIPProperties();
IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();
return ipstat.BytesReceived;
}
示例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";
}
示例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";
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
}
}