excel - 通过 Excel ping 多台计算机,并在单独的列中具有 IP 地址
问题描述
我需要一个自动 ping 工具,因为我的网络中有 70 台计算机,而且我厌倦了cmd
每次都 ping 它们。所以我有这张我已经完成的excel表(大部分)。
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
解决方案
这对我有用
Sub temp()
Set WshShell = CreateObject("WScript.Shell")
RowCount = Worksheets("Sheet1").UsedRange.Rows.Count
For i = 1 To RowCount
Url = Worksheets("Sheet1").Cells(i, 1).Value
cmd = "ping " + Url
Set WshShellExec = WshShell.Exec(cmd)
result = WshShellExec.StdOut.ReadAll
Worksheets("Sheet1").Cells(i, 2).Value = getIP(result)
If (InStr(result, "Received = 4")) Then
Worksheets("Sheet1").Cells(i, 3).Value = "Online"
End If
Next
End Sub
Function getIP(result)
ip = Split(result, vbNewLine)(1)
startIndex = InStr(ip, "[") + 1
endIndex = InStr(ip, "]")
getIP = Mid(ip, startIndex, endIndex - startIndex)
End Function
推荐阅读
- javascript - 如何让投影始终面朝下旋转物体
- powershell - 在 Azure DevOps 中使用 Powershell cmdlet
- java - 在 Android Java 中通过 WebView 读取 XHMTL 文件
- sqlalchemy - 将项目添加到表时出现 SQLAlchemy 错误
- reactjs - 删除 UI-kit 中网格的左右排列并做出反应
- configuration - 使用托管服务进行静态配置
- azure - Azure devops REST API 注释字段包含额外的 HTML 标记
- ios - 无法在 Mac M1 中存档 ReactNative 项目
- flutter - 如何在颤振中添加侧边栏
- dart - Dart 2.14 中 Enum 接口的用例是什么