Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Grab Default Gateway on Linux
- # Reference -----> http://serverfault.com/questions/31170/how-to-find-the-gateway-ip-address-in-linux
- # Example below using subprocess
- #!/usr/bin/python
- import subprocess
- #pipe = subprocess.Popen(ip route list | awk ' /^default/ {print $3}', stdout=subprocess.PIPE)
- #output = pipe.stdout
- subprocess.call("ip route list | awk ' /^default/ {print $3}'", shell=True)
- # Using the iproute package:
- # get the default route
- Raw Commnad: ip route list | awk ' /^default/ {print $3}'
- Usage Example: os.system("ip route list | awk ' /^default/ {print $3}'")
- # get the default route but limit on eth0 (output may be empty)
- ip route list dev eth0 | awk ' /^default/ {print $3}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement