Of course I meant if 'ip route show' doesn't say the command wasn't found.
- S

On 31/10/2007, Stephen Kyle <jimmykane / gmail.com> wrote:
> On 31/10/2007, K. R. <mcse / palstek.ch> wrote:
> > Hi @all
> >
> > How can I find out the mac address from the default gateway with a ruby
> > script?
> > Does exist any methods to read it out? The script runs on a linux
> > distribution...
> I don't know if any methods, exist, but you could hack it up if you
> have the 'ip' package installed on your system, ie. 'ip show route'
> doesn't say the command wasn't found.
> Then you can try:
>
> # get your gateway IP address
> gateway = `ip route
> show`.match(/default.*/)[0].match(/\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?/)[0]
> # get the mac address for the gateway
> mac_address = `ip neigh
> show`.match(/#{gateway}.*/)[0].match(/..:..:..:..:..:../)[0]
>
> Steve (abuser of match)
>
> >
> > thanks for your comment!
> > --
> > Posted via http://www.ruby-forum.com/.
> >
> >
>