Re: Find out the mac address



On 31/10/2007, K. R. <mcse@xxxxxxxxxx> 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/.



.



Relevant Pages

  • Re: Wireless laptop roaming through various access points
    ... Whichever interface has the default route pointing to it, ... It is possible to assign more than one default gateway in the ... What needs to change is the ARP table, which maps the MAC address to ...
    (alt.internet.wireless)
  • Re: Network Horror
    ... >gateway, and I have tried a route add 0.0.0.0 through the same gateway ... but WinME and WinXP machines can not. ... The IP gets the MAC and communications are MAC to MAC so if you ...
    (comp.unix.sco.misc)
  • Re: TCPIP:DNS Dual interfaces and domain names
    ... > Since most of the IP traffic for the mac goes to the internet, ... > efficient to have its default gateway set to the router. ... > route available for the second subnet served by VELO. ...
    (comp.os.vms)
  • Re: TCPIP:DNS Dual interfaces and domain names
    ... > Since most of the IP traffic for the mac goes to the internet, ... > efficient to have its default gateway set to the router. ... > route available for the second subnet served by VELO. ...
    (comp.os.vms)
  • Re: Remove Default Gateway
    ... getting the same error with the full script including DHCP ... I can't get the gateway to remove. ... For Each objNetAdapter in colNetAdapters ... >> For Each objNetAdapter In colNetAdapters ...
    (microsoft.public.windows.server.scripting)