gpt4 book ai didi

http - 检查http连接vbscript

转载 作者:可可西里 更新时间:2023-11-01 17:08:17 24 4
gpt4 key购买 nike

我需要用vbscript检查http连接

我想 ping 主机,看看主机是否响应

我需要测试到特定端口的连接,为什么不也使用 url

你有解决办法吗?

最佳答案

你可以这样尝试:

Option Explicit
Dim Title,strHost
Title = "Check Connection"
strHost = "www.stackoverflow.com"
if Ping(strHost) = True then
MsgBox "Host " & DblQuote(strHost) & " contacted",vbInformation,Title
Else
MsgBox "Host " & DblQuote(strHost) & " could not be contacted",vbCritical,Title
end if
'***********************************************************************************
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode <> 0 then
Ping = False
'WScript.Echo "Status code is " & objRetStatus.StatusCode
else
Ping = True
'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
end if
next
End Function
'***********************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'************************************************************************************

关于http - 检查http连接vbscript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31073653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com