[VB 6/98]Ping-Funktion

Hallo,

ich bräuchte eine Pingroutine fürs LAN aber nicht auf DOS-Ebene.

MfG CB

Hi,
aus dem API-Guide (www.allapi.net):

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 Sub Form\_Load()
 'KPD-Team 2000
 'URL: http://www.allapi.net/
 'E-Mail: [email protected]
 Const HostName = "www.geocities.com"
 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
 Call 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
 MsgBox "Unable to Create File Handle"
 Exit Sub
 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
 MsgBox "Timeout"
 End If
 If EchoReply.Status = 0 Then
 MsgBox "Reply from " + HostName + " (" + rIP + ") recieved after " + Trim$(CStr(EchoReply.RoundTripTime)) + "ms"
 Else
 MsgBox "Failure ..."
 End If
 Call IcmpCloseHandle(hFile)
 Call WSACleanup
End Sub

Gruß

J.

[Bei dieser Antwort wurde das Vollzitat nachträglich automatisiert entfernt]

Hallo,

Danke.
War genau das was ich gesucht habe.

MfG CBothe