Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env ruby -wKU
def ip_route_match(command, regex)
command.split("\n").select { |l| l =~ regex }.first.to_s[/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/] || ''
c = ' dev eth1 proto kernel scope link src dev lo scope link
default via dev eth1'
# c = %x{/sbin/ip route list match #{ip}}
p ip_route_match(c, /^default via /) # => ''
p ip_route_match(c, /via /) # => ''
p ip_route_match(c, /^default crap /) # => ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.