Ping über VB?

  • VB6

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Gast.

    Ping über VB?

    ist es möglich einen anderen Rechner über VB anzupingen? ich mein jetzt nicht über ne shell (blalbal) sonder z.b. über winsock? und wenn ja, wie erkenne ich ob es ein reply gab oder ob der zielhost nicht erreichbar ist?
    <pre>
    '------------------------------------------------
    ' IP anpingen
    '------------------------------------------------
    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_optINFORMATION
    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_optINFORMATION
    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 IcmpCreateFile Lib "icmp.dll" () As Long
    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_optINFORMATION, ReplyBuffer As IP_ECHO_REPLY, _
    ByVal ReplySize As Long, ByVal TimeOut As Long) As Boolean

    Private Const SOCKET_ERROR = 0

    Public Function Ping(ByVal Server As String) As Long
    ' Funktion um den Ping zu einer IP zu erhalten
    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_optINFORMATION
    Dim EchoReply As IP_ECHO_REPLY
    Dim HostName As String

    Ping = -1 'Rückgabe anfangs auf -1 setzen

    Server = Replace(Server, "http://", vbNullString)
    Server = Replace(Server, "ftp://", vbNullString)
    Server = Replace(Server, "/", vbNullString)
    If InStr(1, Server, ":") <> 0 Then
    Server = Mid$(Server, 1, InStr(1, Server, ":") - 1)
    End If

    Call WSAStartup(&H101, lpWSAdata)

    If GetHostByName(Server + String(64 - Len(Server), 0)) <> SOCKET_ERROR Then
    CopyMemory hHostent.h_name, ByVal GetHostByName(Server + String(64 - Len(Server), 0)), Len(hHostent)
    CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
    CopyMemory Address, ByVal AddrList, 4
    End If

    hFile = IcmpCreateFile()
    If hFile = 0 Then
    'Bei Fehler abbrechen
    Exit Function
    End If

    OptInfo.TTL = 255

    'Ping senden
    If IcmpSendEcho(hFile, Address, String(32, "0"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 1000) Then
    rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3))
    If EchoReply.Status = 0 Then Ping = EchoReply.RoundTripTime
    End If
    End Function
    </pre>

    Besucht auch mein anderes Forum:
    Das Amateurfilm-Forum

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()