+ Reply to Thread
Results 1 to 1 of 1

Ping an IP

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2013
    Location
    around
    MS-Off Ver
    Excel 2010
    Posts
    1

    Ping an IP

    Hi guys,

    Could someone help me modify a little bit this code to suit my needs.
    I would like the macro to check a range of cells and add the info ( false , true) next to the range that i am pinging.

    i have a pourly code atempt :

    Sub TestPinger()
       Dim blnResponse As Boolean, lngStatus As ICMP_ECHO_REPLY
    
       For Each tmpcell In Range("a1:a20").SpecialCells(2, 2)
       
       If blnResponse = ping(tempcell, lngStatus) = True Then
       tmpcell.Offset(0, 1) = "ok"
       Else
       tmpcell.Offset(0, 1) = "not ok"
       End If
       Next
    I receive an error : Variable not defined.

    Could someone help a noob to modify this code for my needs?


    Quote Originally Posted by romperstomper View Post
    Not with that method, I don't think. You could use API functions instead - simplistic version below. The Ping function returns True if successful:
    Option Explicit
    
    Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
    
    Private Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal cp As String) As Long
    
    Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal IcmpHandle As Long) As Long
    
    Private Declare Function IcmpSendEcho Lib "icmp.dll" _
       (ByVal IcmpHandle As Long, _
        ByVal DestinationAddress As Long, _
        ByVal RequestData As String, _
        ByVal RequestSize As Long, _
        ByVal RequestOptions As Long, _
        ReplyBuffer As ICMP_ECHO_REPLY, _
        ByVal ReplySize As Long, _
        ByVal timeout As Long) As Long
     
    Private Type IP_OPTION_INFORMATION
       Ttl             As Byte
       Tos             As Byte
       Flags           As Byte
       OptionsSize     As Byte
       OptionsData     As Long
    End Type
     
    Public Type ICMP_ECHO_REPLY
       address         As Long
       Status          As Long
       RoundTripTime   As Long
       DataSize        As Long
       Reserved        As Integer
       ptrData                 As Long
       Options        As IP_OPTION_INFORMATION
       data            As String * 250
    End Type
    
    Public Function ping(strAddress As String, Reply As ICMP_ECHO_REPLY) As Boolean
    
    Dim hIcmp As Long
    Dim lngAddress As Long
    Dim lngTimeOut As Long
    Dim strSendText As String
    
    'Short string of data to send
    strSendText = "blah"
    
    ' timeout value in ms
    lngTimeOut = 1000
    
    'Convert string address to a long
    lngAddress = inet_addr(strAddress)
    
    If (lngAddress <> -1) And (lngAddress <> 0) Then
            
        hIcmp = IcmpCreateFile()
        
        If hIcmp <> 0 Then
            'Ping the destination IP
            Call IcmpSendEcho(hIcmp, lngAddress, strSendText, Len(strSendText), 0, Reply, Len(Reply), lngTimeOut)
    
            'Reply status
            ping = (Reply.Status = 0)
            
            'Close the Icmp handle.
            IcmpCloseHandle hIcmp
        Else
            ping = False
        End If
    Else
        ping = False
    End If
    
    End Function
    
    Sub TestPinger()
       Dim blnResponse As Boolean, lngStatus As ICMP_ECHO_REPLY
       blnResponse = ping("10.100.1.1", lngStatus)
       Debug.Print blnResponse
    End Sub
    Last edited by arlu1201; 10-21-2013 at 01:38 AM. Reason: Corrected code tags.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Converting a Ping Log to Average Ping per Hour Chart
    By AndroidNine in forum Excel General
    Replies: 7
    Last Post: 08-22-2013, 01:38 AM
  2. Ping a URL
    By DjDATZ in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-22-2010, 04:32 PM
  3. Ping an IP (using the IP from a cell)
    By Chris424 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-18-2009, 10:08 AM
  4. [SOLVED] vba ping
    By Brian in forum Excel General
    Replies: 2
    Last Post: 10-04-2005, 01:05 PM
  5. [SOLVED] ping in excel
    By Andy Mohan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-21-2005, 07:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1