关于本地网络流量
想写一个局域网流量查询软件,经网上搜索,搜到以下代码While 1$s1=0
$s2=0
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s1=$s1+$wbemObject.BytesReceivedPerSec
Next
sleep(1000)
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s2=$s2+$wbemObject.BytesReceivedPerSec
Next
$dd=$s2-$s1
MsgBox(1,"提示","每秒流量:"&$dd,10)
sleep(10)
WEnd个人不懂得wmi,求高手把这个改成一函数,用来返回当前流量 有代码改函数很简单啊!
前面加个 func xxx()
后面加个 endfunc
就搞定了! 二楼。。。扯了点。。。
我要函数返回 $dd的值。。
如果只是二楼说的只是加funcendfunc...估计进了函数就出不来了 While 1
ToolTip("当前流量为:" & liuliang() & " 字节/秒", @DesktopWidth - 150, @DesktopHeight - 50)
WEnd
Func liuliang()
While 1
$s1=0
$s2=0
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s1=$s1+$wbemObject.BytesReceivedPerSec
Next
sleep(1000)
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s2=$s2+$wbemObject.BytesReceivedPerSec
Next
$dd=$s2-$s1
;~ MsgBox(1,"提示","每秒流量:"&$dd,10)
Return $dd
sleep(20)
WEnd
EndFunc 至少应该改成这样子吧。。。呵呵While 1
ToolTip("当前流量为:" & liuliang() & " 字节/秒", @DesktopWidth - 150, @DesktopHeight - 50)
Sleep(500)
WEnd
Func liuliang()
$s1=0
$s2=0
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s1=$s1+$wbemObject.BytesReceivedPerSec
Next
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s2=$s2+$wbemObject.BytesReceivedPerSec
Next
$dd=$s2-$s1
Return $dd
EndFunc还是谢谢楼上.. While 1
If MsgBox(5, "提示", "每秒流量:" & net(), 10)=4 Then
Sleep(10)
ContinueLoop
Else
ExitLoop
EndIf
WEnd
Func net()
$s1 = 0
$s2 = 0
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet = $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s1 = $s1 + $wbemObject.BytesReceivedPerSec
Next
Sleep(1000)
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet = $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s2 = $s2 + $wbemObject.BytesReceivedPerSec
Next
$dd = $s2 - $s1
Return $dd
EndFunc 本帖最后由 朱雅琼 于 2010-8-4 11:31 编辑
有谁帮忙把发送(BytesSendPersec )也写一下么。。。或者有哪位高手把这些写成UDF...
万恶的wmi,我看着头大..!
我试了一下,下面这样子不行Func _Up()
$s1=0
$s2=0
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s1=$s1+$wbemObject.BytesSendPersec
Next
Sleep(1000)
$strComputer = "."
$wbemServices = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$wbemObjectSet= $wbemServices.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
For $wbemObject In $wbemObjectSet
$s2=$s2+$wbemObject.BytesSendPersec
Next
$dd=$s2-$s1
Return $dd
EndFunc 哪位高手。。。。。帮忙写一下啊...
页:
[1]