Get data usage since last reboot by command line

3

For an automated batch-tool that monitors network usage, I would like to get the following, red underlined values using the Windows command line:

enter image description here

That is, I want to get the number of bytes uploaded and downloaded (network activity) since the last system reboot using a command (Windows 10).

I already tried netstat -e (using this command: for /F "tokens=2,3" %%a in ('netstat -e ^| find "Bytes"') do set "received=%%a" & set "sent=%%b"), but for some reason, it outputs almost ten times as many bytes as the control panel.

So how can this be done?

sigalor

Posted 2015-08-01T16:07:54.813

Reputation: 385

may be netsats output is in bits. Try multiply it with 8 and compare it. – totti – 2015-08-13T05:46:38.353

@totti netstat explicitly says "Bytes"... – Michel de Ruiter – 2019-03-11T11:34:10.657

Answers

6

If it's OK to use the PowerShell, use the Get-NetAdapterStatistics cmdlet.

PS C:\> $stat = Get-NetAdapterStatistics –Name WiFi PS C:\> $stat.ReceivedBytes 70081089484 PS C:\> $stat.SentBytes 137824135690

There is a blog post about getting network adapter statistics using PowerShell at technet.

Josef says Reinstate Monica

Posted 2015-08-01T16:07:54.813

Reputation: 1 230

If I execute these commands, they only output 0 for me. Even if I just type Get-NetAdapterStatistics all numbers are zeroes, although the control panel clearly shows a value of more than 100 megabytes. – sigalor – 2015-08-11T18:49:00.577

There has to be something broken then. Try to run it in an elevated command prompt and as another user and see if that changes anything. – Josef says Reinstate Monica – 2015-08-12T08:08:38.477

In case this helps, it's also something I'm also having a problem with.

The basic Get-NetAdapterStatistics command is producing output of 0 bytes for only two of my interfaces: named "Ethernet 2" (a disconnected adapter via onboard) and "Bluetooth Network Connection". However, my actual network is "Ethernet". I tried to add -InterfaceDescription "Ethernet" but it says there's no object found with that property.

This was attempted with both elevated and non-elevated PowerShell prompts using both x86 and x64 variants. – psouza4 – 2015-08-12T17:32:13.560

None of these methods change anything. I also tried turning WiFi off and on and reactivating it in the control panel, but nothing changes. – sigalor – 2015-08-12T18:16:54.497

0

Both the netstat -e and the Connection Status box use "Bytes" as the Unit.

netstat -e has existed for a long time, so -i assume- would be bugfree.

BUT, netstat may be counting all interfaces, including loopback.

I did not believe it before either, but Powershell (as indicated by Josef above) seems to be the route of least friction.

Alex Stragies

Posted 2015-08-01T16:07:54.813

Reputation: 1 320

0

I finally figured out a solution that works. I compared the netstat's and control panel's output and found out that netstat shows almost exactly 6 times (yes, six. this is completely illogical...) as many bytes as the control panel. So you just have to divide netstat -e's output bytes by six and you have the real data usage.

sigalor

Posted 2015-08-01T16:07:54.813

Reputation: 385

1I suspect that bytes are being counted multiple times as they pass through filters such as packet inspection, virtual adapters, etc. The multiplier you're seeing may likely vary from system to system. – psouza4 – 2015-08-13T17:38:01.113