pusofalse 发表于 2009-1-8 18:04:50

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

如题,可能会用到的两个函数RasEnumConnections/RasGetConnectionStatistics,存在于RasAPI.dll中。

[ 本帖最后由 pusofalse 于 2009-1-28 20:34 编辑 ]

pusofalse 发表于 2009-1-9 21:33:39

自己顶一个,希望能得到解答,先谢了...

pusofalse 发表于 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;" & _
                "char szDeviceType;char szDeviceName;" & _
                "char szPhoneBook;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 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)

sxd 发表于 2009-1-28 22:08:10

我用简单的 _GetIP ( )

pusofalse 发表于 2009-1-28 23:20:54

_GetIP() 不是获取公网IP的吗? 如何能够获取上网时间?
还是说 我用的_GetIP()跟sxd兄的_GetIP()不一样~? 请赐教。

sxd 发表于 2009-1-28 23:37:06

你一定要原谅我的眼神:face (37):
看走眼了

ceoguang 发表于 2009-1-29 05:43:50

原帖由 pusofalse 于 2009-1-28 20:32 发表 http://www.autoitx.com/images/common/back.gif
终于解决了。。。
#include

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


$tagRasConn...
LZ能不能给个原出处的链接?有些问题想请教下作者!

pusofalse 发表于 2009-1-30 14:26:47

回复 7# ceoguang 的帖子

都是从MSDN上学来的。http://msdn.microsoft.com/en-us/library/aa377284(VS.85).aspx

dunphy 发表于 2014-10-7 15:57:54

回复 3# pusofalse


WHYWIN764位旗舰系统,AU3--3,3,12,0弹出Error on getting Connettion info
怎么没获取到,晕哦。。

lin6051 发表于 2014-10-8 10:26:24

回复 9# dunphy


    xp 32 也一样啊
页: [1]
查看完整版本: 如何调用API获取上网时间。