2

Is there an easy way (via a script perhaps) to get the cumulative bytes sent and received from a NIC on Windows Server 2008?

For example, the NIC currently shows around 18 MB of sent data and 765 MB of received data.

Since my server provider does not provide an easy way to see the monthly bandwidth usage, getting the NIC data seems to be the most reliable one.

I know I can use PRTG to get the current usage data via SNMP, but it will only be an average since the sensor checks every 60 seconds.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
smartins
  • 3,808
  • 7
  • 42
  • 54

5 Answers5

7

In PowerShell (CTP2v3), the commands below will help. (I have three interfaces). However, once the NIC was restarted, this information will zero out.

$computer = "LocalHost";
$namespace = "root\CIMV2";
$Tcpip_NI = Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -computername $computer -namespace $namespace;
$Tcpip_NI | Select BytesReceivedPersec, BytesSentPersec, BytesTotalPersec;

$netsh_interface_stats = netsh interface ip show interface;
$netsh_interface_stats | Select-string "In Octets";
$netsh_interface_stats | Select-string "Out Octets";
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 3
    also (without PowerShell) `wmic path Win32_PerfRawData_Tcpip_NetworkInterface get BytesReceivedPersec,BytesSentPersec,BytesTotalPersec` – ZJR Jun 02 '11 at 02:55
2

Does netstat -e help? It doesn't seem to distinguish between NICs, though you may get your maintenance interface traffic mixed into that as well.

Otherwise this sounds like something for WMI and PowerShell.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joey
  • 344,408
  • 85
  • 689
  • 683
1

You could use an IronRuby or IronPython script and use the System.Net.NetworkInformation namespace although it would probably be easier to whip up a quick C# or VB.NET console application.

You probably need the class IPv4InterfaceStatistics.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sipsorcery
  • 30,273
  • 24
  • 104
  • 155
0

Just a brief note:

The following works perfectly for me - a heads up that the number wraps negative and you will need to build in some logic for that. I'm operating in a mixed environment and do not have PowerShell available on everything, so my solution is to use WMIC:

wmic Win32_PerfRawData_Tcpip_NetworkInterface Get BytesReceivedPersec,BytesSentPersec,BytesTotalPersec
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TDrudge
  • 747
  • 5
  • 5
-1

I found an existing solution for my own problem, PRTG Network Monitor version 7.

It has sensors to interface with WMI and get the network card data. Very nice :)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
smartins
  • 3,808
  • 7
  • 42
  • 54