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 129 130 131 132 133 134 135
| Option Explicit
Const SOCKET_ERROR = 0
Private Type WSAdata
wVersion As Integer
wHighVersion As Integer
szDescription(0 To 255) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
Private Type Hostent
h_name As Long
h_aliases As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Private Type IP_OPTION_INFORMATION
TTL As Byte
Tos As Byte
Flags As Byte
OptionsSize As Long
OptionsData As String * 128
End Type
Private Type IP_ECHO_REPLY
Address(0 To 3) As Byte
Status As Long
RoundTripTime As Long
DataSize As Integer
Reserved As Integer
data As Long
Options As IP_OPTION_INFORMATION
End Type
Private Declare Function GetHostByName Lib _
"wsock32.dll" Alias "gethostbyname" _
(ByVal HostName As String) As Long
Private Declare Function WSAStartup Lib _
"wsock32.dll" (ByVal wVersionRequired&, _
lpWSAdata As WSAdata) As Long
Private Declare Function WSACleanup Lib "wsock32.dll" _
() As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, _
ByVal cbCopy As Long)
Private Declare Function IcmpCreateFile Lib "icmp.dll" _
() As Long
Private Declare Function IcmpCloseHandle Lib "icmp.dll" _
(ByVal HANDLE As Long) As Boolean
Private Declare Function IcmpSendEcho Lib "ICMP" _
(ByVal IcmpHandle As Long, ByVal DestAddress As Long, _
ByVal RequestData As String, _
ByVal RequestSize As Integer, RequestOptns As _
IP_OPTION_INFORMATION, ReplyBuffer As IP_ECHO_REPLY, _
ByVal ReplySize As Long, ByVal TimeOut As Long) As Boolean
Private Function IP_connect(HostName)
Dim hFile As Long, lpWSAdata As WSAdata
Dim hHostent As Hostent, AddrList As Long
Dim Address As Long, rIP As String
Dim OptInfo As IP_OPTION_INFORMATION
Dim EchoReply As IP_ECHO_REPLY
WSAStartup &H101, lpWSAdata
If GetHostByName(HostName + String(64 - Len(HostName), 0)) <> SOCKET_ERROR Then
CopyMemory hHostent.h_name, ByVal GetHostByName(HostName + String(64 - Len(HostName), 0)), Len(hHostent)
CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
CopyMemory Address, ByVal AddrList, 4
End If
hFile = IcmpCreateFile()
If hFile = 0 Then
IP_connect = "Unable to Create File Handle"
Exit Function
End If
OptInfo.TTL = 255
If IcmpSendEcho(hFile, Address, _
String(32, "A"), 32, OptInfo, EchoReply, _
Len(EchoReply) + 8, 2000) Then
rIP = CStr(EchoReply.Address(0)) + _
"." + CStr(EchoReply.Address(1)) + "." + _
CStr(EchoReply.Address(2)) + "." + _
CStr(EchoReply.Address(3))
Else
IP_connect = "Timeout"
End If
If EchoReply.Status = 0 Then
IP_connect = "Reply from " + HostName + " (" + rIP _
+ ") received after " + _
Trim$(CStr(EchoReply.RoundTripTime)) + "ms"
Else
IP_connect = "Failure ..."
End If
IcmpCloseHandle (hFile)
WSACleanup
End Function
Sub Boucle_Sur_Selection()
Dim Sel As Range
Dim Cel As Range
Dim message As String
Set Sel = Selection
For Each Cel In Sel
message = IP_connect(Cel.Value)
ActiveCell = Cel
ActiveCell.Offset(0, 1) = message
ActiveCell.Offset(0, 2) = Time
ActiveCell.Offset(1, 0).Range("A1").Select
Next Cel
Columns("A:C").EntireColumn.AutoFit
Set Sel = Nothing
End Sub |
Partager