[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: mac adrress
 
- From: Petr Štetiar <ynezz@...>
 
- Date: Thu, 18 Mar 2010 14:43:15 +0100
 
steve donovan <steve.j.donovan@gmail.com> [2010-03-18 14:46:40]:
> f = io.popen('ipconfig /all')
> line = f:read()
> while line do
>   if line:find 'Ethernet adapter Local Area Connection' then
>     line = f:read()
>     while not line:find 'Physical Address' do line = f:read() end
>     print(line:match(': (.+)'))
>     return
>   end
>   line = f:read()
> end
Don't know if it's portable, but should be faster:
function mac(iface)
        if not iface then
		return nil, 'no interface'
	end
        local f = io.open('/proc/net/arp', 'r')
        if not f then
		return nil, 'open error'
	end
	local match = string.format('%%x*:.*%s', iface)
        local mac = string.match(tostring(f:read('*a')), match)
        if mac then return mac:sub(1, 17), nil end
end
print(mac("eth0"))