【发布时间】:2021-10-19 01:28:59
【问题描述】:
我需要一个自动 ping 工具,因为我的网络中有 70 台计算机,我厌倦了每次都通过 cmd ping 它们。所以我有这张我已经完成的工作表(大部分)。
A 列包含我手动编写的计算机名称
B 列:它应该(但不)在 A 列中写出计算机的 IP 地址
C 列:根据 ping 显示计算机是在线还是离线。
D 列:我也手动输入了一些内容,以了解谁坐在哪台计算机后面,只是用户名。
我有两个按钮,ping 和 stop ping。他们工作正常。我怎样才能通过按下ping 按钮,让它通过column A 中的所有计算机,并同时显示它们的IP 以及它们是否在线?
当然,不必通过 excel 来完成,如果您有更好的解决方案,可以很好地了解我需要清楚地看到的所有 3 件事(comp name、comp ip、online/offline)和有用户名的第四件事会很高兴。
请帮帮我,我很绝望:
Dim objshell, boolcode
Set objshell = CreateObject("Wscript.Shell")
boolcode = objshell.Run("ping -n 1 -w 1000 " & strip, 0, True)
If boolcode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'_________________________
Sub PingSystem()
Dim strip As String
Do Until Sheet1.Range("G9").Value = "STOP"
Sheet1.Range("G9").Value = "Ping"
For introw = 1 To ActiveSheet.Cells(65536, 2).End(xlUp).Row
strip = ActiveSheet.Cells(introw, 2).Value
If Ping(strip) = True Then
ActiveSheet.Cells(introw, 3).Interior.ColorIndex = 0
ActiveSheet.Cells(introw, 3).Font.Color = RGB(0, 0, 0)
ActiveSheet.Cells(introw, 3).Value = "Online"
ActiveSheet.Cells(introw, 3).Font.Color = RGB(0, 200, 0)
Else
ActiveSheet.Cells(introw, 3).Interior.ColorIndex = 0
ActiveSheet.Cells(introw, 3).Font.Color = RGB(200, 0, 0)
ActiveSheet.Cells(introw, 3).Value = "Offline"
ActiveSheet.Cells(introw, 3).Interior.ColorIndex = 6
End If
If Sheet1.Range("G9").Value = "STOP" Then
Exit For
End If
Next
Loop
Sheet1.Range("G9").Value = "Stop ping"
End Sub
Sub stop_ping()
Sheet1.Range("G9").Value = "STOP"
End Sub
【问题讨论】:
-
您说“A 列:包含我手动编写的计算机名称”,但您的代码
strip = ActiveSheet.Cells(introw, 2).Value正在 ping B 列中的值? -
那是暂时存在的,因为我首先尝试读取静态 IP。同时它被改变了,我只是忘了从这个粘贴的版本中移动它。感谢您的关注。
标签: excel vba automation ping system-administration