Traceroute multiple IP's from text file

I am looking for a way to import a text file of multiple IP addresses (around 2000), have the prog/utility read the address and loop through each one performing a windows traceroute and outputing the results to another text file. I am willing to take the time to write this, but want to know if anyone out there knows of either how to do it, or if it's already been done as to not duplicate efforts. Any help or advice is greatly appreciated.

Thank you.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

bobbit31Connect With a Mentor Commented:

I've modified it to do what you need:

Put the declarations code in the above link in a module

and here's your form code:

basically have a text file named iplist.txt (each ip on different line)
it will output a file for each ip named traceRoute_<ip>.txt

Option Explicit

Dim strOutput As String

Private Sub Command1_Click()

    Dim ff As Integer
    Dim ip As String
    ff = FreeFile
    Open App.Path & "\iplist.txt" For Input As #ff
    Do While Not EOF(ff)
        Line Input #ff, ip
        TraceRT ip, 1, 32
    Close (ff)

End Sub

Public Function TraceRT(ip As String, numPackets As Integer, charsPerPacket As Integer)

   Dim ipo As ICMP_OPTIONS
   Dim echo As ICMP_ECHO_REPLY
   Dim ttl As Integer
   Dim ttlAdjust As Integer
   Dim hPort As Long
   Dim nChrsPerPacket As Long
   Dim dwAddress As Long
   Dim sAddress As String
   Dim sHostIP As String
   '' for file write
   Dim outFile As Integer
   outFile = FreeFile
  'the chars per packet - can be between 32 and 128
   If charsPerPacket < 32 Then charsPerPacket = 32
   If charsPerPacket > 128 Then charsPerPacket = 128
   nChrsPerPacket = charsPerPacket
   If SocketsInitialize() Then
     'convert the address into an internet address.
     'ie returns 1982874833 when passed
      dwAddress = inet_addr(ip)
     'open an internet file handle
      hPort = IcmpCreateFile()
      If hPort <> 0 Then
        strOutput = "Tracing Route to " + ip + ":" & vbCrLf & vbCrLf
        'The heart of the call. See the VBnet
        'page description of the TraceRt TTL
        'member and its use in performing a
        'Trace Route.
         For ttl = 1 To 255
           'set the IPO time to live
           'value to the current hop
            ipo.ttl = ttl
           'Call the API.
           'Two items of consequence happen here.
           'First, the return value of the call is
           'assigned to an 'adjustment' variable. If
           'the call was successful, the adjustment
           'is 0, and the Next will increment the TTL
           'to obtain the next hop. If the return value
           'is 1, 1 is subtacted from the TTL value, so
           'when the next increments the TTL counter it
           'will be the same value as the last pass. In
           'doing this, routers that time out are retried
           'to ensure a completed route is determined.
           '(The values in the List1 show the actual
           ' hops/tries that the method made.)
           'i.e. if the TTL = 3 and it times out,
           '     adjust = 1 so ttl - 1 = 2. On
           '     encountering the Next, TTL is
           '     reset to 3 and the route is tried again.
           'The second thing happening concerns the
           'sHostIP member of the call. When the call
           'returns, sHostIP will contain the name
           'of the traced host IP.  If it matches the
           'string initially used to create the address
           '(above) were at the target, so end.
            ttlAdjust = TraceRTSendEcho(hPort, _
                                        dwAddress, _
                                        nChrsPerPacket, _
                                        sHostIP, _
                                        echo, _
            ttl = ttl - ttlAdjust
           'need some processing time
            If sHostIP = ip Then

              'we're done
              'write to file
               Open App.Path & "\traceRoute_" & ip & ".txt" For Output As #outFile
               strOutput = strOutput & "TraceRoute Complete"
               Print #outFile, strOutput
               Close (outFile)
               Exit For

            End If

         Next ttl

        'clean up
         Call IcmpCloseHandle(hPort)
      Else: MsgBox "Unable to Open an Icmp File Handle", vbOKOnly, "VBnet TraceRT Demo"
      End If  'If hPort
     'clean up
      Call SocketsCleanup
   Else: MsgBox "Unable to initialize the Windows Sockets", vbOKOnly, "VBnet TraceRT Demo"
   End If  'if SocketsInitialize()

End Function

Private Function ShowResults(timeToLive As Byte, _
                        tripTime As Long, _
                        sHostIP As String) As String
   Dim sTripTime As String
   Dim buff As String
   Dim tmp As String

  'format a string representing
  'the round trip time
   Select Case tripTime
      Case Is < 10:   sTripTime = "<10 ms"
      Case Is > 1200: sTripTime = "*"
      Case Else:      sTripTime = CStr(tripTime) & " ms"
   End Select
  'cache the textbox
   buff = strOutput
  'create a new entry
   tmp = "Hop #" & vbTab & _
          CStr(timeToLive) & vbTab & _
          sTripTime & vbTab & _
          sHostIP & vbCrLf

  'update textbox
   strOutput = buff & tmp
End Function

Private Function TraceRTSendEcho(hPort As Long, _
                                 dwAddress As Long, _
                                 nChrsPerPacket As Long, _
                                 sHostIP As String, _
                                 echo As ICMP_ECHO_REPLY, _
                                 ipo As ICMP_OPTIONS) As Integer

   Dim sData As String
   Dim sError As String
   Dim sHostName As String
   Dim ttl As Integer
  'create a buffer to send
   sData = String$(nChrsPerPacket, "a")
   If IcmpSendEcho(hPort, _
                   dwAddress, _
                   sData, _
                   Len(sData), _
                   ipo, _
                   echo, _
                   Len(echo) + 8, _
                   2400) = 1 Then
      'a reply was received, so update the display
       sHostIP = GetIPFromAddress(echo.Address)
       ShowResults ipo.ttl, echo.RoundTripTime, sHostIP
      'return 0 to continue with retrieval
       TraceRTSendEcho = 0
      'a timeout was received, so set the
      'return value to 1. In the TraceRT
      'calling routine, the TTL will be
      'de-incremented by 1, causing the
      'for / next to retry this hop.
       TraceRTSendEcho = 1
   End If
End Function

yes but no. i don't think anyone has come up with the marvelous idea of reading the IP addresses from a file. but i have made a tool that will ping and trace route a whole subnet. we use it at work to map out a network.
Richie_SimonettiIT OperationsCommented:
Hi tomtomtom123,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: Richie_Simonetti and bobbit31

tomtomtom123, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer
per recommendation

Community Support Moderator @Experts Exchange

points for Richie_Simonetti at:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.