Created
April 1, 2016 14:32
-
-
Save henriquemenezes/a99f13da957515023e78aea30d6c0a48 to your computer and use it in GitHub Desktop.
Get default gateway IP in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gw = `ip route show`[/default.*/][/\d+\.\d+\.\d+\.\d+/] |
you can also have multiple GW and this command will explode: you get a multiline string
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found this while Googling. But just wanted to point out that this snippet assumes a Linux environment, or that a Mac user has installed something comparable to
ip
as in this SuperUser post.