Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. import re
  2. ips =[]
  3. hops =[]
  4. time=[]
  5.  
  6. output = '''
  7. Tracing route to www.google.com [216.58.210.228]
  8. over a maximum of 30 hops:
  9.  
  10.  1     7 ms     3 ms     3 ms  192.168.1.1
  11.  2     *       75 ms     *     10.13.255.10
  12.  3    73 ms    26 ms    25 ms  62.169.249.253
  13.  4    80 ms    27 ms    26 ms  62.169.249.174
  14.  5     *        *        *     Request timed out.
  15.  6    27 ms    25 ms    28 ms  195.22.193.45
  16.  7    43 ms    50 ms    44 ms  89.221.39.4
  17.  8    46 ms    45 ms    46 ms  72.14.216.248
  18.  9    49 ms    48 ms    45 ms  72.14.238.133
  19. 10    61 ms    61 ms    60 ms  209.85.253.114
  20. 11    81 ms    78 ms    86 ms  72.14.234.11
  21. 12    73 ms   106 ms    89 ms  72.14.232.77
  22. 13    81 ms    81 ms    79 ms  209.85.253.11
  23. 14    77 ms    78 ms    78 ms  66.249.94.47
  24. 15    78 ms    79 ms    80 ms  216.58.210.228
  25.  
  26. Trace complete.
  27. '''
  28.  
  29. for line in output.splitlines():
  30.     if re.match('\s+\d+', line):
  31.         cols = line.split()
  32.         print cols
  33.         if line.endswith('Request timed out.'):   # I had to replace this with if line.endswith('Request timed out.\r\n'):
  34.             hop, times, ip = cols[0], '* * *', 'Request timed out.'
  35.         else:
  36.             hop, times, ip = cols[0], ' '.join(cols[1:-1]), cols[-1]
  37.         ips.append(ip)
  38.         hops.append(hop)
  39.         time.append(times)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement