I have this command in Ubuntu:
bgpq3 -4 AS-YAHOO-JP-2 -m 24 -l Google
the output is a list of prefixes:
ip prefix-list Google permit 14.137.224.0/19
ip prefix-list Google permit 27.111.76.0/22
ip prefix-list Google permit 27.121.128.0/17
ip prefix-list Google permit 27.133.224.0/22
ip prefix-list Google permit 27.133.240.0/22
ip prefix-list Google permit 27.133.240.0/24
ip prefix-list Google permit 27.133.241.0/24
ip prefix-list Google permit 27.133.242.0/24
ip prefix-list Google permit 27.133.243.0/24
how can i put the output to a list and use each line (as example send them to a database) I dont want to save them first to a file.txt
i am using this command but is does'nt help because the results are stored in a text file.
os.system("bgpq3 -4 AS-YAHOO-JP-2 -m 24 -l Google > list.txt")
Please help me figure this out!!!
I think, you could use subprocess module. This module replaces some older modules and functions. Official document is here: https://docs.python.org/3/library/subprocess.html#module-subprocess
import subprocess
res = subprocess.Popen('bgpq3 -4 AS-YAHOO-JP-2 -m 24 -l Google', shell=True,
universal_newlines=True,
stdout=subprocess.PIPE).communicate()[0]
for line in res.split('\n'):
print(line)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.