0

I am new to Perl and a little stumped on parsing the lines for a traceroute. This is typical of the output that I am challenged with.

 3  someURL.net (184.106.126.128)  0.579 ms someURL.net (184.106.126.124)  0.742 ms  0.719 ms

Note how the 1st and 2nd routes use a different IP address. This will change; e.g., sometimes the hops will use all the same like this:

3  someURL.net (184.106.126.128)  0.579 ms  0.742 ms  0.719 ms

...or, each hop could have a different route, or they could all be the same. I would like to use some regex, etc. in Perl to format the output like this:

3|url~ip~time|url~ip~time|url~ip~time

I'm not sure if I should loop through the individual words somehow, or if it is easier to do it all with regex. Any solutions or hints appreciated.

2
  • So the output from the example input would be this? 3|someURL.net~184.106.126.128~0.579 ms|someURL.net~184.106.126.124~0.742 ms|someURL.net~184.106.126.124~0.719 ms Commented Oct 25, 2011 at 20:27
  • @MetaEd Almost. I was not articulate about the time. That is correct, except there would be no " ms" Commented Oct 25, 2011 at 20:33

2 Answers 2

5

Would it not be easier to use a traceroute module for perl? Is there any reason you need to parse raw traceroute output? (If just as an exercise for learning regex, sure.. but?)

Net::Traceroute would be what I'd use.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @mjbnz. This is an interesting tool (I am new to Perl). I installed it and am playing with it a little. It is not immediately apparent to me if this tool can give output pertaining to each hop like ip and time_per_hop.
Take a look at the hop_query_host() and hop_query_time() methods.
0

would this regex work

((\w+?\.\w+?)\ (\(\d+?\.\d+?\.\d+?\.\d+?\))(\ \d+?\.\d+?\ ms)+\ )+
     URL                  IP                    TIME

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.