[python-win32] Getting Network Information/Statistics

Tim Roberts timr at probo.com
Tue Jan 22 19:20:03 CET 2008


sai rabbit wrote:
> I want to get bytes sent and received in total and by each application 
> if possible. I tried winpdh and winpdhutil but it reports the wrong 
> number for Received in XP and doesn't seem to work for network stats 
> in Vista:
>
> [code]
> >>> import win32pdh
> >>> intf = 'Intel[R] PRO_100 Network Connection'
> >>> hq = win32pdh.OpenQuery()
> >>> cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, 
> None, -1, 'Bytes Received/sec') )
> >>> hc = win32pdh.AddCounter( hq, cp )
> >>> type,val = win32pdh.GetFormattedCounterValue( hc, 
> win32pdh.PDH_FMT_LONG )
>
> Traceback (most recent call last):
>   File "<pyshell#5>", line 1, in <module>
>     type,val = win32pdh.GetFormattedCounterValue( hc, 
> win32pdh.PDH_FMT_LONG )
> error: (-2147481645, 'GetFormattedCounterValue', 'No error message is 
> available'
> [/code]

-2147481645 is 0x800007D3, which is PDH_CSTATUS_ITEM_NOT_VALIDATED.  
"The data item has been added to the query, but has not been validated 
or accessed."  You're sure that you have the interface name correct?  Is 
that exactly what it says for the connection name when you do "ipconfig"?

Why do you think the number is wrong on XP?  Remember that this is bytes 
per second, not bytes since forever.

Windows doesn't track network statistics on a per-process basis.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list