目前已经是完成了之前预想的功能,写了一个vbs 脚本,放在了目标机器上,远程开机后,有网络后就会触发 脚本的执行。脚本主要有如下功能,启动tailscale ,虽然已经将 tailscale 设置为了开机自起,获取tailscale 的邻居ip , 对邻居ip 进行ping 操作(这边已经去掉了对一次没ping 通的,进行多次ping 操作,估摸着比较复杂吧,以及耗时),并且始终无法将没有ping 通的对象加入数组,所以这个功能也就没加,还加入了对命令执行的结果,记录日志。
Function pingip(ByRef objShell,ByRef match,ByRef objFile)
Set objExecObject = objShell.Exec ("%comspec% /c ping " & match.value )
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
loop
objFile.WriteLine "ping time: " & Now() & " " & strText
Dim result
If objExecObject.ExitCode =0 Then
'WScript.Echo "ping tong le"
objFile.WriteLine "time: " & Now() & "IP:" & match.value & " " & " ping tong le"
result=0
pingip=result
Else
result=1
pingip=result
End If
End Function
Dim newMatches, objFSO,objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\lws\Desktop\tailscale.log",8,True)
Set objShell = CreateObject("WScript.Shell")
Set objShellTail = CreateObject("WScript.Shell")
Set objExecObject = objShellTail.Exec ("%comspec% /c tailscale up ")
Wscript.Sleep 5000
Set objExecObject = objShell.Exec ("%comspec% /c tailscale status ")
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
loop
'msgbox strText
objFile.WriteLine "tailscale up info: " & Now()
Set objRegExp=New RegExp
objRegExp.pattern="fd7a:115c:a1e0::\d"
objRegExp.Global = True
Set colMatches=objRegExp.Execute(strText)
If colMatches.Count > 0 Then
For Each match in colMatches
ping1_result=pingip(objShell,match,objFile)
Next
End If
objFile.Close
Set objFile = Nothing
Set objFSO= Nothing