Find out the mac address

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...

thanks for your comment!

···

--
Posted via http://www.ruby-forum.com/.

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)

···

On 31/10/2007, K. R. <mcse@palstek.ch> wrote:

thanks for your comment!
--
Posted via http://www.ruby-forum.com/\.

this may not help you directly, but:

cfp:~ > ruby -r macaddr -e' p Mac.addr '
"00:17:f2:d5:c1:ec"

gem install macaddr

regards.

a @ http://codeforpeople.com/

···

On Oct 31, 2007, at 4:02 AM, K. R. 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...

thanks for your comment!
--
Posted via http://www.ruby-forum.com/\.

--
share your knowledge. it's a way to achieve immortality.
h.h. the 14th dalai lama

parse the output from tracert or traceroute??
K. R. wrote:9

···

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...

thanks for your comment!

--
Posted via http://www.ruby-forum.com/\.

If you know the IP address of the gateway, then parse the output of
the 'arp -n <IP>' command. It's reasonably portable and easy to
parse.

···

On Oct 31, 2007 3:02 AM, 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...

--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing & replay tools for Unix
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety. -- Benjamin Franklin

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/\.
>
>

thanks for the reply, but I search a solution to find out the mac
address from the default gw not my own mac address....

···

--
Posted via http://www.ruby-forum.com/.

Quoth Stephen Kyle:

> 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]
or .match(/((?:\d{1,3}\.){3}(?:\d{1,3}))/)
(group (3 groups of 1-3 decimals followed by a period) with (a group of 1-3
decimals))

# get the mac address for the gateway
mac_address = `ip neigh
show`.match(/#{gateway}.*/)[0].match(/..:..:..:..:..:../)[0]

this could also be more correct:
/((?:[\da-f]{2}:){5})(?:[\da-f]{2}))/
So it doesn't match *any character*, but instead valid MAC addresses.

Steve (abuser of match)

>
> thanks for your comment!

Regards,

···

On 31/10/2007, K. R. <mcse@palstek.ch> wrote:

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertillnoon.com/