找回密码
 加入
搜索
查看: 5288|回复: 9

如何调用API获取上网时间。

[复制链接]
发表于 2009-1-8 18:04:50 | 显示全部楼层 |阅读模式
如题,可能会用到的两个函数RasEnumConnections/RasGetConnectionStatistics,存在于RasAPI.dll中。

[ 本帖最后由 pusofalse 于 2009-1-28 20:34 编辑 ]
 楼主| 发表于 2009-1-9 21:33:39 | 显示全部楼层
自己顶一个,希望能得到解答,先谢了...
 楼主| 发表于 2009-1-28 20:32:53 | 显示全部楼层
终于解决了。。。
#include <Date.au3>

;Global const $RAS_MaxEntryName = 256
;Global const $RAS_MaxDeviceType = 16
;Global const $RAS_MaxDeviceName =128
;Global const $Max_Path = 260


$tagRasConn = "dword dwSize;hWnd hRasConn;char szEntryName[257];" & _
                "char szDeviceType[17];char szDeviceName[129];" & _
                "char szPhoneBook[261];dword dwSubEntry;int GuidEntry;" & _
                "dword dwFlags;int Luid;int GuidCorrelationId"

$tRasConn = DllStructCreate($tagRasConn)
DllStructSetData($tRasConn, "dwSize", DllStructGetSize($tRasConn))
$ptRasConn = DllStructGetPtr($tRasConn)

$lpCb = DllStructCreate("byte")
DllStructSetData($lpCb, 1, DllStructGetSize($tRasConn))

$pRes = DllStructCreate("ulong")

$res = DllCall("RasAPI32.Dll", "dword", "RasEnumConnections", _
                "ptr", $ptRasConn, _
                "dword*", DllStructGetPtr($lpCb), _
                "dword*", DllStructGetPtr($pRes))

$hRasConn = DllStructGetData($tRasConn, "hRasConn")
$EntryName = "Entry Name: " & DllStructGetData($tRasConn, "szEntryName") & @CrLf
$DeviceType = "Device Type: " & DllStructGetData($tRasConn, "szDeviceType") & @CrLf
$DeviceName = "Device Name: " & DllStructGetData($tRasConn, "szDeviceName") & @CrLf
$PhoneBook = "Phone Book: " & DllStructGetData($tRasConn, "szPhoneBook") & @CrLf
$SubEntry = "Sub Entry: " & DllStructGetData($tRasConn, "swSubEntry") & @CrLf
$GuidEntry = "Logon Session: " & DllStructGetData($tRasConn, "GuidEntry") & @CrLf

$dwFlags = DllStructGetData($tRasConn, "dwFlags")
$ConnForAll = "Connection For All users: " & (BitAnd($dwFlags, 1) = 1) & @CrLf
$CredentialsDefault = "Credentials Default: " & (BitAnd($dwFlags, 2) = 2) & @CrLf
$LocallyUniqueId = "Locally Unique Identifier: " & DllStructGetData($tRasConn, "Luid") & @CrLf
$CorrelationId = "CorrelationId: " & DllStructGetData($tRasConn, "GuidCorrelationId") & @CrLf


$tagRasStats = "dword dwSize;dword dwBytesXmited;dword dwBytesRcved;" & _
        "dword dwFramesXmited;dword dwFramesRcved;dword dwCrcErr;" & _
        "dword dwTimeoutErr;dword dwAlignmentErr;dword dwHardwareOverRunErr;" & _
        "dword dwFramingErr;dword dwBufferOverRunErr;dword dwCompressionRatioIn;" & _
        "dword dwCompressionRatioOut;dword dwBps;dword dwConnectDuration"

$tRasStats = DllStructCreate($tagRasStats)
DllStructSetData($tRasStats, "dwSize", DllStructGetSize($tRasStats))
$ptRasStats = DllStructGetPtr($tRasStats)


$GetStatistics = DllCall("RasAPI32.Dll", "dword", "RasGetConnectionStatistics", _
                "hWnd", $hRasConn, "ptr", $ptRasStats)
If $GetStatistics[0] then
        msgBox(48, 'Error', 'Error on getting Connection Info.')
        Exit(-1)
EndIf

Local $result = "Handle of Connection: " & $hRasConn & @crLf & $EntryName & $DeviceType & _
        $DeviceName & $PhoneBook & $SubEntry & $GuidEntry & $ConnForAll & _
        $CredentialsDefault & $LocallyUniqueId & $CorrelationId & @crLf

$Result &= "Bytes Transmitted(Bytes): " & DllStructGetData($tRasStats, "dwBytesXmited") & @crLf & _
        "Bytes Received(Bytes): " & DllStructGetData($tRasStats, "dwBytesRcved") & @crLf & _
        "Cyclic Redundancy Error: " & DllStructGetData($tRasStats, "dwCrcErr") & @crLf & _
        "Timeout Error: " & DllStructGetData($tRasStats, "dwTimoutErr") & @crLf & _
        "Alignment Error: " & DllStructGetData($tRasStats, "dwAlignmentErr") & @crLf & _
        "Hardware Overrun: " & DllStructGetData($tRasStats, "dwHardwareOverrunErr") & @crLf & _
        "Framing Error: " & DllStructGetData($tRasStats, "dwFramingErr") & @crLf & _
        "Buffer Overrun: " & DllStructGetData($tRasStats, "dwBufferOverrunErr") & @crLf & _
        "Speed of Connection(MB): " & DllStructGetData($tRasStats, "dwBps") / 1000000 & @crLf

Local $hour, $min, $sec
$Duration = DllStructGetData($tRasStats, "dwConnectDuration")
_TicksToTime($Duration, $hour, $min, $sec)
$Result &= "Connection Duration: " & stringFormat("%i:%02i:%02i", $hour, $min, $sec)

$tRasConn = 0
$tRasStats = 0

msgBox(64,'', $Result)
发表于 2009-1-28 22:08:10 | 显示全部楼层
我用简单的 _GetIP ( )
 楼主| 发表于 2009-1-28 23:20:54 | 显示全部楼层
_GetIP() 不是获取公网IP的吗? 如何能够获取上网时间?
还是说 我用的_GetIP()跟sxd兄的_GetIP()不一样~? 请赐教。
发表于 2009-1-28 23:37:06 | 显示全部楼层
你一定要原谅我的眼神
看走眼了
发表于 2009-1-29 05:43:50 | 显示全部楼层
原帖由 pusofalse 于 2009-1-28 20:32 发表
终于解决了。。。
[au3]#include

;Global const $RAS_MaxEntryName = 256
;Global const $RAS_MaxDeviceType = 16
;Global const $RAS_MaxDeviceName =128
;Global const $Max_Path = 260


$tagRasConn  ...

LZ能不能给个原出处的链接?有些问题想请教下作者!
 楼主| 发表于 2009-1-30 14:26:47 | 显示全部楼层

回复 7# ceoguang 的帖子

都是从MSDN上学来的。http://msdn.microsoft.com/en-us/library/aa377284(VS.85).aspx
发表于 2014-10-7 15:57:54 | 显示全部楼层
回复 3# pusofalse


WHY  WIN7  64位旗舰系统,AU3--3,3,12,0  弹出Error on getting Connettion info
怎么没获取到,晕哦。。
发表于 2014-10-8 10:26:24 | 显示全部楼层
回复 9# dunphy


    xp 32 也一样啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 12:40 , Processed in 0.071110 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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