vbs obtains the information of the machine and the monitoring and detection of ping

Script background

Sometimes when communicating with non-technical personnel, when you ask them to provide host information or to ping a domain name to detect the health situation, the general personnel may not understand it, which may be a disastrous operation for them, so here we provide a vbs script to send directly to non-technical personnel, and let them double-click it and take a screenshot

Program Ontology

Function GetIPMAC(ComputerName) 
Dim objWMIService,colItems,objItem,objAddress
Set objWMIService = GetObject("winmgmts://" & ComputerName & "/root/cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
 For Each objAddress in objItem.IPAddress
  If objAddress <> "" then
  GetIPMAC = "[Local information] "& vbCrLf & " IP: " & objAddress & vbCrLf & " MAC: " & objItem.MACAddress & vbCrLf & " DNS1: " & objItem.DNSServerSearchOrder(0) & vbCrLf & " DNS2: " & objItem.DNSServerSearchOrder(1)
  Exit For
 End If  
 Next
 Exit For
Next
End Function

Private Function PingHost(strHostOrIP, count)

    On Error Resume Next ' Start Error Handling

    'Set Variables
    Dim objPing, objRetStatus, i, strResult: strResult = ""

    For i = 1 to count
        Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & strHostOrIP & "'")
        For Each objRetStatus in objPing
            If IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 Then
                strResult = "cannot connect"
                'WScript.Echo "Status code is " & objRetStatus.StatusCode
            Else
                strResult = "normal"
                'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
                'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
                'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
            End If
        Next

        ' Error Check
        If Err.Number <> 0 Then
            strResult = "cannot connect"
        End If

        'Check For Success
        If strResult = "normal" Then
            Exit For
        End If
        count = count -1
    Next

    'Return Result
    PingHost = strResult

    On Error GoTo 0 ' End Error Handling

End Function

' ------ SCRIPT CONFIGURATION ------
Dim strHost: strHost = "www.baidu.com"
Dim intCount: intCount = 2
Dim pingHostResult: pingHostResult = PingHost(strHost, intCount)
Dim tip: tip = "[Test results]" & vbCrLf & " Request domain name:" & strHost & vbCrLf & " Connection status:" & pingHostResult & vbCrLf & vbCrLf & "[Hint]" & vbCrLf & " The current connection status is normal. If you cannot access the system, please use the IE9+Browser and try to clear the browser cache. If not, please take a screenshot of the current window and put it in the warehouse or customer service operation group@Feedback from students on duty"
' ------ END CONFIGURATION ------

If pingHostResult = "cannot connect" Then
    tip = "[Test results]" & vbCrLf & " Request domain name:" & strHost & vbCrLf & " Connection status:" & pingHostResult & vbCrLf & vbCrLf & "[Hint]" & vbCrLf & " General information" & vbCrLf &" 1,Tip 1" & vbCrLf & " 2,Tip 2"
End If

Wscript.Echo GetIPMAC(".") & vbCrLf & vbCrLf & tip

Save the above code as. vbs file and send it to non-technical personnel for execution. The effect is as follows:

Tags: Mac

Posted on Mon, 06 Jan 2020 03:10:28 -0800 by Caesar