1个回答
展开全部
Imports vb = Microsoft.VisualBasic
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj, OBJStatus, url, GetText, i
Dim Retrieval
url = "http://www.163.com"
'判断网络是否连接
If url <> "" Then
Retrieval = GetObject("winmgmts:\\.\root\cimv2")
obj = Retrieval.ExecQuery("Select * From Win32_PingStatus Where Address = '" & Mid(url, 8) & "'")
For Each OBJStatus In obj
If vb.Information.IsDBNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
Exit Sub
Else
Exit For '已连接则继续
End If
Next
End If
'通过下载网页头信息获取网络时间
Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open("Get", url, False, "", "")
.setRequestHeader("If-Modified-Since", "0")
.setRequestHeader("Cache-Control", "no-cache")
.setRequestHeader("Connection", "close")
.Send()
If .Readystate <> 4 Then Exit Sub
GetText = .getAllResponseHeaders()
i = InStr(1, GetText, "date:", vbTextCompare)
If i > 0 Then '网页下载成功
i = InStr(i, GetText, ",", vbTextCompare)
GetText = Trim(Mid(GetText, i + 1))
i = InStr(1, GetText, " GMT", vbTextCompare)
GetText = vb.Left(GetText, i - 1)
MsgBox("网络时间:" & GetText)
End If
End With
Retrieval = Nothing
OBJStatus = Nothing
obj = Nothing
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj, OBJStatus, url, GetText, i
Dim Retrieval
url = "http://www.163.com"
'判断网络是否连接
If url <> "" Then
Retrieval = GetObject("winmgmts:\\.\root\cimv2")
obj = Retrieval.ExecQuery("Select * From Win32_PingStatus Where Address = '" & Mid(url, 8) & "'")
For Each OBJStatus In obj
If vb.Information.IsDBNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
Exit Sub
Else
Exit For '已连接则继续
End If
Next
End If
'通过下载网页头信息获取网络时间
Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open("Get", url, False, "", "")
.setRequestHeader("If-Modified-Since", "0")
.setRequestHeader("Cache-Control", "no-cache")
.setRequestHeader("Connection", "close")
.Send()
If .Readystate <> 4 Then Exit Sub
GetText = .getAllResponseHeaders()
i = InStr(1, GetText, "date:", vbTextCompare)
If i > 0 Then '网页下载成功
i = InStr(i, GetText, ",", vbTextCompare)
GetText = Trim(Mid(GetText, i + 1))
i = InStr(1, GetText, " GMT", vbTextCompare)
GetText = vb.Left(GetText, i - 1)
MsgBox("网络时间:" & GetText)
End If
End With
Retrieval = Nothing
OBJStatus = Nothing
obj = Nothing
End Sub
End Class
追问
时间差很多...差了9个小时.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询