Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. import subprocess
  2. import re
  3.  
  4.  
  5.  
  6. proc = subprocess.Popen('tracert -d www.google.com',stdout=subprocess.PIPE,shell=True)
  7.  
  8.  
  9. while True:
  10.         line = proc.stdout.readline()
  11.         if re.match('\s+\d+', line):
  12.             cols = line.split()
  13.             if line.endswith('Request timed out.'):
  14.                 hop, times, ip = cols[0], '* * *', 'Request timed out.'
  15.             else:
  16.                 hop, times, ip = cols[0], ' '.join(cols[1:-1]), cols[-1]
  17.             print hop
  18.             print times
  19.             print ip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement