Skip to content

Instantly share code, notes, and snippets.

@henriquemenezes
Created April 1, 2016 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henriquemenezes/a99f13da957515023e78aea30d6c0a48 to your computer and use it in GitHub Desktop.
Save henriquemenezes/a99f13da957515023e78aea30d6c0a48 to your computer and use it in GitHub Desktop.
Get default gateway IP in Ruby
gw = `ip route show`[/default.*/][/\d+\.\d+\.\d+\.\d+/]
@scottschup
Copy link

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.

@maxadamo
Copy link

maxadamo commented Mar 23, 2020

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