#!/usr/bin/python
# -*- coding: utf-8 -*-

#Python program to switch between default routes each time the script is executed.
#
#Alex Boschmans, Halle, Belgium
#www.boschmans.net
#
#V0.1 - March 2012
#

import os, subprocess

ROUTE1 = "172.20.1.4"
ROUTE2 = "172.20.1.254"

def get_route_info(format=None):
    '''
    return output of netstat input only for internet 4 (not ipV6).
    '''
    # Set up the bash command to execute
    command = subprocess.Popen(['netstat','-r', '-f', 'inet'], shell=False, stdout=subprocess.PIPE)
    if format == "raw":
        result = command.communicate()[0]
    else:
        # Read the result, and split in list according to newline command
        result = command.communicate()[0].split("\n")
    return result

# Find out which route we are on
result = get_route_info()
for line in result:
	line = line.split()
	if "default" in line:
		gateway = line[1]
		interface = line[5]
		print "Default route is %s on interface %s" % (gateway, interface)
		 


