找回密码
 加入
搜索
查看: 4124|回复: 7

[网络通信] 关于本地网络流量

  [复制链接]
发表于 2010-8-3 22:17:44 | 显示全部楼层 |阅读模式
想写一个局域网流量查询软件,经网上搜索,搜到以下代码
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,求高手把这个改成一函数,用来返回当前流量
发表于 2010-8-3 22:32:08 | 显示全部楼层
有代码改函数很简单啊!
前面加个 func xxx()
后面加个 endfunc
就搞定了!
 楼主| 发表于 2010-8-3 22:39:32 | 显示全部楼层
二楼。。。扯了点。。。

我要函数返回 $dd的值。。

如果只是二楼说的只是加func  endfunc...估计进了函数就出不来了
发表于 2010-8-3 22:41:47 | 显示全部楼层
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

评分

参与人数 1金钱 +15 收起 理由
afan + 15

查看全部评分

 楼主| 发表于 2010-8-3 22:53:07 | 显示全部楼层
至少应该改成这样子吧。。。呵呵
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
还是谢谢楼上..
发表于 2010-8-3 23:16:40 | 显示全部楼层
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

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-8-4 10:10:44 | 显示全部楼层
本帖最后由 朱雅琼 于 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
 楼主| 发表于 2010-8-4 11:57:02 | 显示全部楼层
哪位高手。。。。。帮忙写一下啊...
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 12:37 , Processed in 0.077306 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表