Results 1 to 3 of 3

Thread: ping loop

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    RI
    Posts
    25

    ping loop

    I'm trying to get this program to ping a range of ip address. i got it so that it can ping the starting ip address but cannot have it loop so that it will ping all the ip address in between the range.. example...

    ping 192.168.1.1 to 192.168.1.20
    and write the ip status in a log file.

    so far it can ping one ip address, but when i put the code in a loop it doenst ping at all. i double checked the loop code, the loop works. but once i add it to the other code, it stops pinging, the program does not through up anyerrors at or.

    heres the code that i have...
    it will increment the last octect in the ip address.
    example(192.168.1.1 last octet is 1.)
    ------------------------------------------------------------------
    once i add the loop it doesnt work, i get rid of just the loop code and it works. everthing between the DIM INTLOOP and the LOOP text is the code that pings.
    -------------------------------------------------------------------
    Dim intLoop As Integer
    For intLoop = Val(txtText(0).Text) To Val(txtText(7).Text)

    Dim ECHO As ICMP_ECHO_REPLY
    Dim pos As Long
    Dim success As Long

    If SocketsInitialize() Then
    'ping the ip passing the address, text to send, and the ECHO structure.
    success = Ping((txtText(0).Text) & "." & (txtText(1).Text) & "." & (txtText(2).Text) & "." & (txtText(3).Text), (txtText(0).Text), ECHO)

    'display the results
    Dim b As String
    Dim c As String

    b = GetStatusCode(success)
    c = ECHO.RoundTripTime & " ms"
    SocketsCleanup
    Else
    MsgBox "Winsocks for 32-bit Windows environment is not responding."
    End If

    With ListView1.ListItems
    .Add , , (txtText(0).Text) & "." & (txtText(1).Text) & "." & (txtText(2).Text) & "." & (txtText(3).Text)
    End With

    'adds to the second column, 1rst row
    ListView1.ListItems(1).SubItems(1) = b
    ' adds to the fourth column, 1rst row
    ListView1.ListItems(1).SubItems(2) = c

    frmIPLog.List1.AddItem (txtText(0).Text) & "." & (txtText(1).Text & "." & txtText(2).Text & "." & txtText(3).Text) & vbTab & b & vbTab & vbTab & c

    Next intLoop


    if anyone can help me, it would be MUCH appreciated. i just cant figure it out. thanks.
    - Gabe

  2. #2
    bubba
    Guest

    You're not using intloop

    You aren't changing the elements being called in your arrays.

    To properly use the for next, it would be something like this

    For intLoop = Lbound(myarray) to ubound(myarray)

    msgbox myarray(intLoop)

    Next

    You have the elements in your arrays hard-coded.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    RI
    Posts
    25

    Thank You

    Thank you. I'll give it a shot.
    - Gabe

Posting Permissions

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



Click Here to Expand Forum to Full Width