有没有一种简单的方法可以使用 VBScript 验证网络上是否存在服务器?

发布于 2024-08-26 18:53:11 字数 104 浏览 10 评论 0原文

我的最终目标是确定具有特定凭据的特定服务器上的特定数据库正在运行,但此时我会满足于检查并查看服务器是否确实在网络上运行的能力。有人有办法做到这一点吗?我似乎在画一片空白。

迈克尔

I have the eventual goal of determining that a particular database on a particular server with particular credentials is running, but I would settle, at this point, for the ability to check and see if a server is actually up on the network. Does anyone have a way of doing this? I seem to be drawing a blank.

Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

负佳期 2024-09-02 18:53:11

尝试这个

Dim target
Dim result

target= "172.19.130.96"

Set shell = WScript.CreateObject("WScript.Shell")

Set shellexec = shell.Exec("ping " & target) 

result = LCase(shellexec.StdOut.ReadAll)

If InStr(result , "reply from") Then
  WScript.Echo "Server alive"  
Else
  WScript.Echo "Not Alive"
End If

也许有更好的方法,特别是考虑到您的最终目标,但这应该有效,并且至少为您指明了正确的方向。

try this

Dim target
Dim result

target= "172.19.130.96"

Set shell = WScript.CreateObject("WScript.Shell")

Set shellexec = shell.Exec("ping " & target) 

result = LCase(shellexec.StdOut.ReadAll)

If InStr(result , "reply from") Then
  WScript.Echo "Server alive"  
Else
  WScript.Echo "Not Alive"
End If

There maybe better ways especialy given you end goal but this should work and at least point you in the correct direction.

人生戏 2024-09-02 18:53:11

这是使用 Win32_PingStatus WMI 类(注意:此类仅在 Windows XP 及更高版本上可用):

strServer = "stackoverflow.com"

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oPing = oWMI.Get("Win32_PingStatus.Address='"& strServer & "'")

If oPing.StatusCode = 0 Then 
   WScript.Echo "Server is available."
Else
   WScript.Echo "Server is not available."
End If

更多 ping 脚本示例位于:为什么我的 Ping 脚本不能在 Windows 2000 计算机上运行?

Here's an alternative solution that uses the Win32_PingStatus WMI class (note: this class is only available on Windows XP and later):

strServer = "stackoverflow.com"

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oPing = oWMI.Get("Win32_PingStatus.Address='"& strServer & "'")

If oPing.StatusCode = 0 Then 
   WScript.Echo "Server is available."
Else
   WScript.Echo "Server is not available."
End If

More ping script samples here: Why Doesn't My Ping Script Run on Windows 2000 Computers?

欢烬 2024-09-02 18:53:11

如果您更新 ping 命令,使其仅发送一个回显请求,则脚本执行速度会更快,如果您的网络不可靠,这可能不是最好的,但对于本地 LAN 来说它很有用。

Dim target
Dim result

target= "172.19.130.96"

Set shell = WScript.CreateObject("WScript.Shell")

Set shellexec = shell.Exec("ping -n 1 " & target)

result = LCase(shellexec.StdOut.ReadAll)

If InStr(result , "reply from") Then
  WScript.Echo "Server alive"  
Else
  WScript.Echo "Not Alive"
End If

If you update the ping command so it only sends one echo request the script executes faster, if you've got an unreliable network this might not be best but for local LAN it's useful.

Dim target
Dim result

target= "172.19.130.96"

Set shell = WScript.CreateObject("WScript.Shell")

Set shellexec = shell.Exec("ping -n 1 " & target)

result = LCase(shellexec.StdOut.ReadAll)

If InStr(result , "reply from") Then
  WScript.Echo "Server alive"  
Else
  WScript.Echo "Not Alive"
End If
素手挽清风 2024-09-02 18:53:11

要检查数据库服务器是否已启动,您可以使用 nmap 等工具。然后你可以像平常一样使用 exec() 在你的 vbscript 中调用它。

For checking whether your database server is up, you can use tools like nmap. Then you can call it in your vbscript using exec() as per normal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文