1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| Function GetPingResult(Host)
Dim objPing As Object
Dim objStatus As Object
Dim Result As String
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("Select * from Win32_PingStatus Where Address = '" & Host & "'")
For Each objStatus In objPing
Select Case objStatus.StatusCode
Case 0: strResult = "Connected"
Case 11001: strResult = "Buffer too small"
Case 11002: strResult = "Destination net unreachable"
Case 11003: strResult = "Destination host unreachable"
Case 11004: strResult = "Destination protocol unreachable"
Case 11005: strResult = "Destination port unreachable"
Case 11006: strResult = "No resources"
Case 11007: strResult = "Bad option"
Case 11008: strResult = "Hardware error"
Case 11009: strResult = "Packet too big"
Case 11010: strResult = "Request timed out"
Case 11011: strResult = "Bad request"
Case 11012: strResult = "Bad route"
Case 11013: strResult = "Time-To-Live (TTL) expired transit"
Case 11014: strResult = "Time-To-Live (TTL) expired reassembly"
Case 11015: strResult = "Parameter problem"
Case 11016: strResult = "Source quench"
Case 11017: strResult = "Option too big"
Case 11018: strResult = "Bad destination"
Case 11032: strResult = "Negotiating IPSEC"
Case 11050: strResult = "General failure"
Case Else: strResult = "Unknown host"
End Select
GetPingResult = strResult
Next
Set objPing = Nothing
End Function
Sub GetIPStatus()
Dim Cell As Range
Dim ipRng As Range
Dim Result As String
Dim Wks As Worksheet
Set Wks = Worksheets("PING")
' ip hspr
Set ipRng = Wks.Range("C2")
Set RngEnd = Wks.Cells(Rows.Count, ipRng.Column).End(xlUp)
Set ipRng = IIf(RngEnd.Row < ipRng.Row, ipRng, Wks.Range(ipRng, RngEnd))
For Each Cell In ipRng
Result = GetPingResult(Cell)
Cell.Offset(0, 1) = Result
If Result = "Connected" Then
Cell.Offset(0, 1).Interior.Color = RGB(0, 150, 0)
Else
If Result = "Time-To-Live (TTL) expired transit" Then
Cell.Offset(0, 1).Interior.Color = RGB(255, 153, 0)
Else
Cell.Offset(0, 1).Interior.Color = RGB(255, 0, 0)
End If
End If
Next Cell
' ip primaire
Set ipRng = Wks.Range("E2")
Set RngEnd = Wks.Cells(Rows.Count, ipRng.Column).End(xlUp)
Set ipRng = IIf(RngEnd.Row < ipRng.Row, ipRng, Wks.Range(ipRng, RngEnd))
For Each Cell In ipRng
Result = GetPingResult(Cell)
Cell.Offset(0, 1) = Result
If Result = "Connected" Then
Cell.Offset(0, 1).Interior.Color = RGB(0, 150, 0)
Else
If Result = "Time-To-Live (TTL) expired transit" Then
Cell.Offset(0, 1).Interior.Color = RGB(255, 153, 0)
Else
Cell.Offset(0, 1).Interior.Color = RGB(255, 0, 0)
End If
End If
Next Cell
' ip secondaire
Set ipRng = Wks.Range("G2")
Set RngEnd = Wks.Cells(Rows.Count, ipRng.Column).End(xlUp)
Set ipRng = IIf(RngEnd.Row < ipRng.Row, ipRng, Wks.Range(ipRng, RngEnd))
For Each Cell In ipRng
Result = GetPingResult(Cell)
Cell.Offset(0, 1) = Result
If Result = "Connected" Then
Cell.Offset(0, 1).Interior.Color = RGB(0, 150, 0)
Else
If Result = "Time-To-Live (TTL) expired transit" Then
Cell.Offset(0, 1).Interior.Color = RGB(255, 153, 0)
Else
Cell.Offset(0, 1).Interior.Color = RGB(255, 0, 0)
End If
End If
Next Cell
' ip switch
Set ipRng = Wks.Range("I2")
Set RngEnd = Wks.Cells(Rows.Count, ipRng.Column).End(xlUp)
Set ipRng = IIf(RngEnd.Row < ipRng.Row, ipRng, Wks.Range(ipRng, RngEnd))
For Each Cell In ipRng
Result = GetPingResult(Cell)
Cell.Offset(0, 1) = Result
If Result = "Connected" Then
Cell.Offset(0, 1).Interior.Color = RGB(0, 150, 0)
Else
If Result = "Time-To-Live (TTL) expired transit" Then
Cell.Offset(0, 1).Interior.Color = RGB(255, 153, 0)
Else
Cell.Offset(0, 1).Interior.Color = RGB(255, 0, 0)
End If
End If
Next Cell
End Sub |
Partager