Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ping button in an Access database

Posted on 1998-07-08
1
Medium Priority
?
234 Views
Last Modified: 2013-11-13
I need to create a button in my Access database that will ping the IP of the selected client field.
0
Comment
Question by:Lozz
1 Comment
 
LVL 1

Accepted Solution

by:
Geffl earned 400 total points
ID: 1465210
Hi Lozz!

Paste this code in a module and try the function 'Ping'. The hostname can be the computername or IP-Adress.
The function returns true if ping was successfull.

Public RespondingHost As String
Public TraceRT As Boolean
Public TTL As Integer
Public Const WS_VERSION_MAJOR = &H101 \ &H100 And &HFF&
Public Const WS_VERSION_MINOR = &H101 And &HFF&
Public Const MIN_SOCKETS_REQD = 0
Public Function Ping(Host$) As Boolean

    vbWSAStartup                ' Initialize Winsock
    If Not vbGetHostByName(Host$) Then
        WSACleanup
        Exit Function
    End If

    vbIcmpCreateFile            ' Get ICMP Handle
    pIPo.TTL = 255

    Ping = vbIcmpSendEcho       ' Send the ICMP Echo Request

    vbIcmpCloseHandle           ' Close the ICMP Handle

    vbWSACleanup                ' Close Winsock

End Function
Sub vbWSAStartup()
    iReturn = WSAStartup(&H101, WSAdata)

    If iReturn <> 0 Then    ' If WSock32 error, then tell me about it
        MsgBox "WSock32.dll is not responding!", vbOKOnly, "VB4032-ICMPEcho"
    End If

    If LoByte(WSAdata.wVersion) < WS_VERSION_MAJOR Or (LoByte(WSAdata.wVersion) = WS_VERSION_MAJOR And HiByte(WSAdata.wVersion) < WS_VERSION_MINOR) Then
        sHighByte = Trim$(Str$(HiByte(WSAdata.wVersion)))
        sLowByte = Trim$(Str$(LoByte(WSAdata.wVersion)))
        sMsg = "WinSock Version " & sLowByte & "." & sHighByte
        sMsg = sMsg & " is not supported "
        MsgBox sMsg, vbOKOnly, "VB4032-ICMPEcho"
        End
    End If

    If WSAdata.iMaxSockets < MIN_SOCKETS_REQD Then
        sMsg = "This application requires a minimum of "
        sMsg = sMsg & Trim$(Str$(MIN_SOCKETS_REQD)) & " supported sockets."
        MsgBox sMsg, vbOKOnly, "VB4032-ICMPEcho"
        End
    End If
   
    MaxSockets = WSAdata.iMaxSockets
    If MaxSockets < 0 Then
        MaxSockets = 65536 + MaxSockets
    End If

    MaxUDP = WSAdata.iMaxUdpDg
    If MaxUDP < 0 Then
        MaxUDP = 65536 + MaxUDP
    End If
    Description = ""
   
    For i = 0 To WSADESCRIPTION_LEN
        If WSAdata.szDescription(i) = 0 Then Exit For
        Description = Description + Chr$(WSAdata.szDescription(i))
    Next i
    Status = ""
   
    For i = 0 To WSASYS_STATUS_LEN
        If WSAdata.szSystemStatus(i) = 0 Then Exit For
        Status = Status + Chr$(WSAdata.szSystemStatus(i))
    Next i

End Sub
Private Function vbGetHostByName(ByVal HostName$) As Boolean

    Dim szString As String

    Host = HostName$    ' Set Variable Host to Value in Text1.text

    szString = String(64, &H0)
    Host = Host + Right$(szString, 64 - Len(Host))

    If gethostbyname(Host) = SOCKET_ERROR Then          ' If WSock32 error, then tell me about it
        Exit Function
    Else
        PointerToPointer = gethostbyname(Host)          ' Get the pointer to the address of the winsock hostent structure
        CopyMemory Hostent.h_name, ByVal _
        PointerToPointer, Len(Hostent)                  ' Copy Winsock structure to the VisualBasic structure

        ListAddress = Hostent.h_addr_list               ' Get the ListAddress of the Address List
        CopyMemory ListAddr, ByVal ListAddress, 4       ' Copy Winsock structure to the VisualBasic structure
        CopyMemory IPLong, ByVal ListAddr, 4            ' Get the first list entry from the Address List
        CopyMemory Addr, ByVal ListAddr, 4

        vbGetHostByName = True

    End If

End Function
Sub vbGetHostName()
    
    Host = String(64, &H0)      ' Set Host value to a bunch of spaces
    
    If gethostname(Host, HostLen) = SOCKET_ERROR Then   ' This routine is where we get the host's name
        sMsg = "WSock32 Error" & Str$(WSAGetLastError())    ' If WSOCK32 error, then tell me about it
        MsgBox sMsg, vbOKOnly, "VB4032-ICMPEcho"
    Else
        Host = Left$(Trim$(Host), Len(Trim$(Host)) - 1)     ' Trim up the results
        Text1.Text = Host                                   ' Display the host's name in label1
    End If

End Sub
Private Function vbIcmpSendEcho() As Boolean

    szBuffer = "abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefghijklm"
    szBuffer = Left$(szBuffer, 32)
    DoEvents
    bReturn = IcmpSendEcho(hIP, Addr, szBuffer, Len(szBuffer), pIPo, pIPe, Len(pIPe) + 8, 2700)

    If bReturn Then
        vbIcmpSendEcho = (pIPe.Status = 0)
    End If

End Function
Function HiByte(ByVal wParam As Integer)

    HiByte = wParam \ &H100 And &HFF&

End Function
Function LoByte(ByVal wParam As Integer)

    LoByte = wParam And &HFF&

End Function
Sub vbWSACleanup()
    iReturn = WSACleanup()

    If iReturn <> 0 Then    ' If WSock32 error, then tell me about it.
        sMsg = "WSock32 Error - " & Trim$(Str$(iReturn)) & " occurred in Cleanup"
        MsgBox sMsg, vbOKOnly, "VB4032-ICMPEcho"
        End
    End If

End Sub
Sub vbIcmpCloseHandle()

    bReturn = IcmpCloseHandle(hIP)

    If bReturn = False Then
        MsgBox "ICMP Closed with Error", vbOKOnly, "VB4032-ICMPEcho"
    End If

End Sub
Sub vbIcmpCreateFile()

    hIP = IcmpCreateFile()

End Sub


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question