导航:首页 > 网络连接 > vb网络连接状态

vb网络连接状态

发布时间:2023-05-22 16:33:58

❶ vb怎样查看网络连接状态

Winsock.state 是显示当前Winsock 和另一主机连接的状态,它不是显示主机网络信息的.

用InternetGetConnectedState() 函数可以实现.为了方便你调用下面给模快代码你吧..

Private Declare Function InternetGetConnectedState Lib "Wininet.dll" (ByVal Flag As Long, ByVal Reserved As Long) As Long
Public Type Rtn_InetStat
IsConnecting As Boolean
IsModenConnecting As Boolean
IsModenBusy As Boolean
IsLANConnecting As Boolean
IsProxyConnecting As Boolean
End Type
Public Function RtnInetStat() As Rtn_InetStat
RtnInetStat.IsConnecting = RtnNunBooleanA(InternetGetConnectedState(0, 0))
RtnInetStat.IsModenConnecting = RtnNunBooleanB(InternetGetConnectedState(1, 0))
RtnInetStat.IsLANConnecting = RtnNunBooleanB(InternetGetConnectedState(2, 0))
RtnInetStat.IsProxyConnecting = RtnNunBooleanA(InternetGetConnectedState(4, 0))
RtnInetStat.IsModenBusy = RtnNunBooleanA(InternetGetConnectedState(8, 0))
End Function
Private Function RtnNunBooleanA(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanA = False
Else
RtnNunBooleanA = True
End If
End Function
Private Function RtnNunBooleanB(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanB = True
Else
RtnNunBooleanB = False
End If
End Function

获取当前网络是否已连接上:
Msgbox RtnInetStat.IsConnecting

❷ VB检测网络状态

'请试看这个 添加 Command1 修改下面你要检测的IP地址

Private Sub Command1_Click()
MsgBox IIf(CheckServ("192.168.1.1"), "服务器联线中", "服务器未联线") '你的服务器IP地址
End Sub

Public Function CheckServ(Ipadr As String) As Boolean
Dim aa$, bb$, fname$
CheckServ = False
fname = "c:\tmpfile.txt"
Open "c:\testip.bat" For Output As #1
Print #1, "@echo off"
Print #1, "ping " & Ipadr & " > " & fname
Close #1
If Dir(fname) <> "" Then Kill fname
Call Shell("cmd /c " & "c:\testip.bat", vbHide)
'延时5秒内是否得到文档
starttm = Timer
Do
DoEvents
If Dir(fname) <> "" Then
If FileLen(fname) > 10 Then Exit Do '得到文档即退出检测
End If
Loop Until Timer > = starttm + 5
bb = ""
If Dir(fname) <> "" Then
Open fname For Input As #1
While Not EOF(1)
Line Input #1, aa
bb = bb & aa & vbCrLf
Wend
Close #1
End If
CheckServ = IIf(InStr(bb, "Request") > 0, False, True)
If Dir("c:\testip.bat") <> "" Then Kill "c:\testip.bat"
End Function

❸ vb怎么判断网络是否已经连接上

GetHostbyName API可获取域名对应的IP地址,当没有联网状态将会返回一个错误值。所以可利用它来判断是否联网。

Private Sub Form_Load()
If IsConnectedState Then
MsgBox "连接网络"
Else
MsgBox "没有联网"
End If
End Sub

VBScript code复制代码

Option Explicit

Private Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To 256) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type

Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Integer, lpWSAData As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHostname As String) As Long
Private Const WS_VERSION_REQD = &H101

Public Function IsConnectedState() As Boolean
Dim udtWSAD As WSADATA
Call WSAStartup(WS_VERSION_REQD, udtWSAD)
IsConnectedState = CBool(gethostbyname("www..com"))
Call WSACleanup
End Function

阅读全文

与vb网络连接状态相关的资料

热点内容
上海无线网络技术价格对比 浏览:207
4g网络信号箭头 浏览:345
美国无线网络用户数量 浏览:762
天翼通网络在哪里下载 浏览:427
蜂窝式无线网络 浏览:405
网络电视网络接口如何插 浏览:563
网络教育怎么写总结 浏览:976
ios关闭网络与wifi 浏览:54
思科ccna和网络工程师哪个好 浏览:44
王者荣耀网络用哪个dns 浏览:927
如何在虚拟机里面拼接网络 浏览:660
设置更多的网络在哪里 浏览:361
网络机顶盒wifi连接上 浏览:553
网络文化学校的学费是多少 浏览:198
网络电话app软件 浏览:849
中国移动网络电视怎么连接无线 浏览:110
形容无线网络好的词语 浏览:575
路由器装好后电脑没网络 浏览:357
天津大学网络教育工商管理本科学的哪些科目 浏览:907
网购网络安全宣传 浏览:376

友情链接