[python-win32] Getting Network Information/Statistics

>.> twopill at gmail.com
Thu Jan 24 01:04:22 CET 2008


That works for XP but not Vista, I guess M$ changed the API in Vista. Oh by
the way I mean to write win32pdhutil.browse() earlier. Thanks for the help.
I didn't run it as admin in Vista before so I gave your script a try.
The output from your script as run in vista by administrator follows:
[code]
>>> win32pdhutil.browse()
Value of '\Network Interface(Intel[R] PRO_100 VE Network Connection)\Current
Bandwidth' is 100000000.0
Added 'Current Bandwidth' on object 'Network Interface' (machine
\\SAIBOX-01), instance Intel[R] PRO_100 VE Network Connection(0)-parent of
None
>>>
Traceback (most recent call last):
  File
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python25\getrcv.py", line 10, in <module>
    tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG )
error: (-1073738810, 'GetFormattedCounterValue', 'No error message is
available')
>>>
[/code]
I'm new to working in windows and am curious as to how to go about getting
the error codes, I tried hex(1073738810) but thats not right.


On Jan 23, 2008 1:11 PM, Tim Roberts <timr at probo.com> wrote:

>  >.> wrote:
> > I got the interface name from win32util.browse() in Vista and XP. I
> > think XP is Giving me the wrong number because it differs from what
> > I'm reading in perfmon everytime and it seems to be counting down from
> > that number after every subsequent call.
> > ex: perfmon will give me a last of 0.0 and
> >  win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes
> > Received/sec','Intel[R] PRO_100 VE Network Connection - Packet
> > Scheduler Miniport')
> >
> > Will return something like 12107 and will go down every subsequent call.
>
> Insert a call to win32pdh.CollectQueryData(hq) before you fetch the
> counter value.  The counters are only fetched when you send a query, and
> that's done with CollectQueryData.
>
> For me, this produces exactly the same numbers as perfmon:
>
> import win32pdh
> import time
> intf = "NVIDIA nForce Networking Controller - Packet Scheduler Miniport"
> hq = win32pdh.OpenQuery()
> cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None,
> -1, 'Bytes Received/sec') )
> hc = win32pdh.AddCounter( hq, cp )
> for i in range(100):
>     win32pdh.CollectQueryData ( hq )
>    tp,val = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG )
>    print hex(tp),val
>    time.sleep(1)
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080123/a13a8525/attachment-0001.htm 


More information about the python-win32 mailing list