Re: Find out the mac address
- From: "Stephen Kyle" <jimmykane@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 20:02:26 +0900
On 31/10/2007, K. R. <mcse@xxxxxxxxxx> wrote:
Hi @allI don't know if any methods, exist, but you could hack it up if you
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...
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/.
.
- Follow-Ups:
- Re: Find out the mac address
- From: Stephen Kyle
- Re: Find out the mac address
- References:
- Find out the mac address
- From: K. R.
- Find out the mac address
- Prev by Date: Re: Code to DRY
- Next by Date: Re: Find out the mac address
- Previous by thread: Find out the mac address
- Next by thread: Re: Find out the mac address
- Index(es):
Relevant Pages
|