Vous devez interroger WMI pour obtenir cette information. La meilleure façon de le faire à partir de Python est d'exécuter simplement cette VB Script (il a travaillé pour moi):
Option Explicit
On Error Resume Next
dim strComputer
dim wmiNS
dim wmiQuery
dim objWMIService
Dim objLocator
dim colItems
dim objItem
Dim strUsr, strPWD, strLocl, strAuth, iFLag 'connect server parameters
Dim colNamedArguments 'WshNamed object
subCheckCscript 'check to see if running in cscript
Set colNamedArguments = WScript.Arguments.Named
strComputer = colNamedArguments("c")
subCheckArguments
wmiNS = "\root\cimv2"
wmiQuery = "Select BytesTotalPerSec from Win32_PerfFormattedData_Tcpip_NetworkInterface"
strUsr = colNamedArguments("u") '""'Blank for current security. Domain\Username
strPWD = colNamedArguments("p") '""'Blank for current security.
strLocl = "" '"MS_409" 'US English. Can leave blank for current language
strAuth = ""'if specify domain in strUsr this must be blank
iFlag = "0" 'only two values allowed here: 0 (wait for connection) 128 (wait max two min)
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, _
wmiNS, strUsr, strPWD, strLocl, strAuth, iFLag)
Set colItems = objWMIService.ExecQuery(wmiQuery)
For Each objItem in colItems
Wscript.Echo funLine("Name: " & objItem.name)
Wscript.Echo "CurrentBandwidth: " & funConvert("M",objItem.BytesTotalPerSec)
Next
' *** subs are below ***
Sub subCheckCscript
If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then
Wscript.Echo "This script must be run under CScript"
WScript.Quit
End If
end Sub
Sub subCheckArguments
If colNamedArguments.Count < 4 Then
If colNamedArguments.Exists("?") Then
WScript.Echo "Uses Win32_PerfFormattedData_Tcpip_NetworkInterface to determine bandwidth" _
& VbCrLf & "This script can take arguments. It will analyze bandwidth of network adapter"_
& VbCrLf & "This is useful when you want to see the actual bandwidth of a network adapter" _
& VbCrLf & "Perhaps to troubleshoot cases when the adapter autodetects the wrong speed" _
& VbCrLf & "Alternate credentials can ONLY be supplied for remote connections" _
& VbCrLf & "Try this: cscript " & WScript.ScriptName & " [/c:yourcomputername] [/u:domainName\UserName] [/p:password]" _
& VbCrLf & "Example: cscript " & WScript.ScriptName & " /c:london /u:nwtraders\londonAdmin /p:[email protected]" _
& VbCrLf & vbTab & " Connects to a remote machine called london in the nwtraders domain with the londonAdmin user" _
& VbCrLf & vbTab & " account and the password of [email protected] It returns the speed of each network adapter" _
& VbCrLf & "Example: cscript " & WScript.ScriptName _
& VbCrLf & vbTab & " Returns the speed of each network adapter on local machine"
WScript.Quit
End If
WScript.Echo "checking arguments"
If Not colNamedArguments.Exists("c") Then
WScript.Echo "Executing on Local Machine only"
strComputer = "localHost"
End If
If Not colNamedArguments.Exists("u") Then
WScript.Echo "Executing using current user name"
strUsr = ""
End If
If Not colNamedArguments.Exists("p") Then
WScript.Echo "Executing using current user password"
strPWD = ""
End If
End If
If colNamedArguments.Count = 0 Then
Exit Sub
End If
End Sub
Function funConvert(strC,intIN)
Select Case strC
Case "K"
funConvert = formatNumber(intIN/1000) & " KiloBytes"
Case "M"
funConvert = formatNumber(intIN/1000000) & " MegaBytes"
Case "G"
funConvert = formatNumber(intIN/1000000000) & " GigaBytes"
End Select
End Function
Function funLine(lineOfText)
Dim numEQs, separator, i
numEQs = Len(lineOfText)
For i = 1 To numEQs
separator= separator & "="
Next
FunLine = VbCrLf & lineOfText & vbcrlf & separator
End Function
adapté de http://www.itworld.com/nlswindows070320?page=0,1
Copiez et collez le code VB dans un fichier appelé bandwidth.vbs et courir comme ceci à partir de cmd:
cscript bandwidth.vbs
Merci! Il semble que le script montre la bande passante des interfaces pas la vitesse (ie dans mon cas, montre 1000MB pour mon Gigabit Ethernet et 54MB pour mon wlan G) je cherche quelque chose de similaire (j'utilise WMI pour obtenir des disques durs temp et capacité) montre la vitesse réelle de téléchargement/téléchargement (dans mon cas, pour surveiller les torrents sans allumer l'écran du PC). J'ai trouvé ce programme http://www.floriangilles.com/software/netspeedmonitor/ qui est ce dont j'ai besoin mais qui n'a pas d'interface de commande ... – Manuel
Regardez plutôt Win32_NetworkAdapter.Speed au lieu de CurrentBandwidth ... http: //msdn.microsoft.com/en-us/library/aa394554(VS.85).aspx –
MaxSpeed et vitesse. Le premier renvoie la vitesse maximale pour l'adaptateur réseau. La seconde renvoie l'utilisation actuelle de la bande passante. Les deux renvoie la valeur en bits par seconde. –