用vbs脚本写一个局域网扫描
时间: 2023-03-29 12:02:57 浏览: 231
我可以回答这个问题。您可以使用以下vbs脚本来扫描局域网:
```
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
strIP = IPConfig.IPAddress(i)
If InStr(strIP, ".") > Then
strPrefix = Left(strIP, InStrRev(strIP, "."))
For j=1 To 254
strTestIP = strPrefix & j
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address='" & strTestIP & "'")
For Each objStatus in objPing
If objStatus.StatusCode = Then
WScript.Echo "IP Address: " & strTestIP & " is online."
End If
Next
Next
End If
Next
End If
Next
```
这个脚本将扫描您的局域网,并显示在线的IP地址。请注意,您需要以管理员身份运行此脚本。
阅读全文