導航:首頁 > 網路連接 > 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網路連接狀態相關的資料

熱點內容
怎麼弄網路問卷 瀏覽:832
IP13USB共享網路 瀏覽:649
廣電寬頻如何登錄網路 瀏覽:397
有信網路電話怎麼發簡訊 瀏覽:689
無線網路鏈接不可用 瀏覽:335
網路友情為什麼都這么虛偽 瀏覽:682
網路通話設置不上網 瀏覽:114
三星網路恢復設置在哪塊 瀏覽:262
設置網路限速 瀏覽:868
如何讓電腦里連接家裡的網路 瀏覽:478
手機上免費網路電話哪個好用嗎 瀏覽:983
軟體逆向和網路入侵哪個難 瀏覽:703
網路延時顯示fail是什麼意思 瀏覽:20
報考的網路課程有哪些 瀏覽:661
上海無線網路技術價格對比 瀏覽:208
4g網路信號箭頭 瀏覽:346
美國無線網路用戶數量 瀏覽:763
天翼通網路在哪裡下載 瀏覽:427
蜂窩式無線網路 瀏覽:405
網路電視網路介面如何插 瀏覽:563

友情鏈接