import os routes = os.popen('route print').readlines() for a in routes: print(a) #print([a for a in os.popen('route print').readlines() if ' 0.0.0.0 ' in a])