|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
以前挺好有的一段代码,现在也不能用了,
现在各大网站的反扒机制越来越严了,
- Private Sub Command1_Click()
- Dim obj, OBJStatus, url, GetText, i
- Dim Retrieval
- url = "http://www.163.com"
- '判断网络是否连接
- If url <> "" Then
- Set Retrieval = GetObject("winmgmts:\\.\root\cimv2")
- Set obj = Retrieval.ExecQuery("Select * From Win32_PingStatus Where Address = '" & Mid(url, 8) & "'")
- For Each OBJStatus In obj
- If IsNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
- Exit Sub
- Else
- Exit For '已连接则继续
- End If
- Next
- End If
- '通过下载网页头信息获取网络时间
- Set 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 = Left(GetText, i - 1)
- MsgBox "网络时间:" & GetText
- End If
- End With
- Set Retrieval = Nothing
- Set OBJStatus = Nothing
- Set obj = Nothing
- End Sub
复制代码
|
|