明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1284|回复: 3

[求助]请教各位...

[复制链接]
发表于 2003-2-25 11:46:00 | 显示全部楼层 |阅读模式
我想写个程序,用于监控连接和断开因特网的动作。
VB/Win2000/ADSL
我的想法:监控TCP/IP。
请各位出手指教...
 楼主| 发表于 2003-2-26 09:02:00 | 显示全部楼层

Up

发表于 2003-2-26 19:16:00 | 显示全部楼层

如内,不知是否合用

'API函数定义
    Dim eR As EIGCInternetConnectionState
    Dim sMsg As String
    Dim sName As String
    Dim bConnected As Boolean
     
    Private Declare Function InternetSetDialState Lib "wininet.dll" _
     (ByVal lpszConnectoid As String, ByVal dwState As Long, _
     ByVal dwReserved As Long) As Long
     
    Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
    (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
    ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
     
    Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
     Alias "InternetGetConnectedStateExA" _
     (ByRef lpdwFlags As Long, _
     ByVal lpszConnectionName As String, _
     ByVal dwNameLen As Long, _
     ByVal dwReserved As Long _
     ) As Long
    Private Enum EIGCInternetConnectionState
     INTERNET_CONNECTION_MODEM = &H1&
     INTERNET_CONNECTION_LAN = &H2&
     INTERNET_CONNECTION_PROXY = &H4&
     INTERNET_RAS_INSTALLED = &H10&
     INTERNET_CONNECTION_OFFLINE = &H20&
     INTERNET_CONNECTION_CONFIGURED = &H40&
    End Enum
     
    'InternetConnected 函数判断是否连接到Internet的函数
    '获得是否以及通过何中方式连接到Internet上
    Private Function InternetConnected(Optional ByRef eConnectionInfo _
     As EIGCInternetConnectionState, Optional ByRef _
     sConnectionName As String) As Boolean
     
     Dim dwFlags As Long
     Dim sNameBuf As String
     Dim lR As Long
     Dim iPos As Long
     
     sNameBuf = String$(513, 0)
     lR = InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0&)
     eConnectionInfo = dwFlags
     iPos = InStr(sNameBuf, vbNullChar)
     If iPos > 0 Then
     sConnectionName = Left$(sNameBuf, iPos - 1)
     ElseIf Not sNameBuf = String$(513, 0) Then
     sConnectionName = sNameBuf
     End If
     InternetConnected = (lR = 1)
    End Function
     
    'InternetConnected 函数的调用
   
    Sub main()
     Dim bConnected As Boolean
     Dim eR As EIGCInternetConnectionState
     Dim sName As String
     Dim sMsg As String
     
      '检测是否已经以及使用什么方法连接到Internet
   
     bConnected = InternetConnected(eR, sName)
     
     
     '根据获得的结果输出
     If (eR And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then
     sMsg = sMsg & "使用modem连接到Internet." & vbCrLf
     End If
     If (eR And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then
     sMsg = sMsg & "使用内部网连接到Internet." & vbCrLf
     End If
     If (eR And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then
     sMsg = sMsg & "通过代理服务器连接到Internet." & vbCrLf
     End If
     If (eR And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then
     sMsg = sMsg & "现在连接处于离线状态." & vbCrLf
     End If
     If (eR And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then
     sMsg = sMsg & "连接已经被设定." & vbCrLf
     Else
     sMsg = sMsg & "没有设定好的连接." & vbCrLf
     End If
     If (eR And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then
     sMsg = sMsg & "本机已经安装了远程访问服务功能." & vbCrLf
     End If
     
     '显示连接名称
     If bConnected Then
     sMsg = "已连接到Internet,连接名称: " & sName & vbCrLf & vbCrLf & sMsg
     Else
     sMsg = "没有连接到Internet,连接名称: " & sName & vbCrLf & vbCrLf & sMsg
     End If
    Debug.Print sMsg
    End Sub
 楼主| 发表于 2003-2-27 09:21:00 | 显示全部楼层

谢谢,让我试试...

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 18:47 , Processed in 0.163358 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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