0

I need to run a subprocess to do traceroute.

I'd like to filter traceroute output, when it output the first ASN (something like AS11223344). Write this ASN and IP to a specific file.

How to find AS\d+ in a subprocess output?? Then save to a file.

Then terminate the subprocess.

The output is a lot of things like this : 222.221.28.57 20.37 ms AS4134

PotatoChips
  • 189
  • 2
  • 12
  • 2
    what specific part have you difficulties with? 1- how to run a subprocess? 2- how to capture its output? 3- how to terminate the subprocess? – jfs Dec 09 '17 at 09:34
  • How to capture the output and filter to what I need?The subprocess will show a lot of example output , but I just need the first line which has the first ASN and IP. – PotatoChips Dec 09 '17 at 10:00
  • [(1)](https://docs.python.org/2/library/subprocess.html#subprocess.Popen) [(2)](https://docs.python.org/2/library/subprocess.html#subprocess.STDOUT) [(3)](https://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method) [(4)](https://docs.python.org/2/library/subprocess.html#subprocess.Popen.kill) – zwer Dec 09 '17 at 10:15
  • [How do you search subprocess output in Python for a specific word?](https://stackoverflow.com/a/23280092/4279) – jfs Dec 09 '17 at 10:17
  • But the output word is not certain.I just know the line must contains ```AS```,Then? – PotatoChips Dec 09 '17 at 10:37
  • @PotatoChips "how to find `AS\d+` in a string?" should be a separate question. Try to limit your questions to a single issue (so that the answers would be more informative and so that they could help somebody else too). – jfs Dec 09 '17 at 11:23

0 Answers0