Solved

Traceroute multiple IP's from text file

Posted on 2002-05-21
5
531 Views
Last Modified: 2010-05-02
Hello,
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.
0
Comment
Question by:tomtomtom123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Expert Comment

by:sk33v3
ID: 7025426
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.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7025475
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 37 total points
ID: 7025588
from http://www.mvps.org/vbnet/code/internet/tracert.htm

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
    Loop
   
    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 209.68.48.118
      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, _
                                        ipo)
     
            ttl = ttl - ttlAdjust
           'need some processing time
            DoEvents
       
           
            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
     
   Else
     
      '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

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7818330
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
0
 

Expert Comment

by:SpideyMod
ID: 7910139
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

points for Richie_Simonetti at:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20505888.html
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 76
How does CurrentUser work? 10 44
How to Add / Edit Windows Menu 4 82
Passing a Text Box name to a Sub 6 104
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 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