MAC Address

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

MAC Address

Jon Smirl
Is there a standardized way in lua of getting the MAC address of the
default network interface?

--
Jon Smirl
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Mike Panetta
There isn't even a standard way in C to do that... ;)

Mike

On Sat, Feb 12, 2011 at 11:21 PM, [hidden email] <[hidden email]> wrote:
Is there a standardized way in lua of getting the MAC address of the
default network interface?

--
Jon Smirl
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Thomas Harning Jr.
Let alone a way to define "default network interface".  Or is there?
Say I have 2 NICs, which one is default?

On Sat, Feb 12, 2011 at 11:41 PM, Mike Panetta <[hidden email]> wrote:

> There isn't even a standard way in C to do that... ;)
>
> Mike
>
> On Sat, Feb 12, 2011 at 11:21 PM, [hidden email] <[hidden email]>
> wrote:
>>
>> Is there a standardized way in lua of getting the MAC address of the
>> default network interface?
>>
>> --
>> Jon Smirl
>> [hidden email]
>>
>
>



--
Thomas Harning Jr.

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Leo Razoumov
On Sat, Feb 12, 2011 at 23:44, Thomas Harning Jr. <[hidden email]> wrote:
> Let alone a way to define "default network interface".  Or is there?
> Say I have 2 NICs, which one is default?
>

The one which is associated with a default route is a default interface.
On Linux one can get it via "route -n". From Lua one can use
os.popen("route -n") and then parse the line with 0.0.0.0 destination
(default route) and extract the corresponding interface name.

--Leo--

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Jeff Pohlmeyer
On Sat, Feb 12, 2011 at 11:43 PM, Leo Razoumov wrote:

> On Sat, Feb 12, 2011 at 23:44, Thomas Harning Jr. wrote:
>> Let alone a way to define "default network interface".  Or is there?
>> Say I have 2 NICs, which one is default?

> The one which is associated with a default route is a default interface.
> On Linux one can get it via "route -n". From Lua one can use
> os.popen("route -n") and then parse the line with 0.0.0.0 destination
> (default route) and extract the corresponding interface name.

I am using pppoe on my machine and "route" tells me 0.0.0.0
is ppp0, but that still doesn't tell me which NIC is ppp0
associated with.

 - Jeff

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Andrew Cannon
Jeff Pohlmeyer wrote:

> On Sat, Feb 12, 2011 at 11:43 PM, Leo Razoumov wrote:
>
>> On Sat, Feb 12, 2011 at 23:44, Thomas Harning Jr. wrote:
>>> Let alone a way to define "default network interface".  Or is there?
>>> Say I have 2 NICs, which one is default?
>
>> The one which is associated with a default route is a default interface.
>> On Linux one can get it via "route -n". From Lua one can use
>> os.popen("route -n") and then parse the line with 0.0.0.0 destination
>> (default route) and extract the corresponding interface name.
>
> I am using pppoe on my machine and "route" tells me 0.0.0.0
> is ppp0, but that still doesn't tell me which NIC is ppp0
> associated with.
>
>  - Jeff
>

for that you need 'ifconfig ppp0'

- Andrew




Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Axel Kittenberger
MAC is someting ethernet specific, not every network interface has to
have one. Correct me if I'm wrong, but why should a PPP-connection
have a mac adress anyway? Its a point-to-point connection, no need to
address something on Layer 2 in the OSI Modell where Mac belongs to.

Also not every computer must have a "default network interface", what
if you are not connected to the internet and thus not have a default
route? Or you are part of the backbone? (unlikely but possible :-)

I wonder what the usecase is that warrents wanting to know "mac of the
default network interface"?

On Sun, Feb 13, 2011 at 11:18 AM, Andrew Cannon <[hidden email]> wrote:

> Jeff Pohlmeyer wrote:
>> On Sat, Feb 12, 2011 at 11:43 PM, Leo Razoumov wrote:
>>
>>> On Sat, Feb 12, 2011 at 23:44, Thomas Harning Jr. wrote:
>>>> Let alone a way to define "default network interface".  Or is there?
>>>> Say I have 2 NICs, which one is default?
>>
>>> The one which is associated with a default route is a default interface.
>>> On Linux one can get it via "route -n". From Lua one can use
>>> os.popen("route -n") and then parse the line with 0.0.0.0 destination
>>> (default route) and extract the corresponding interface name.
>>
>> I am using pppoe on my machine and "route" tells me 0.0.0.0
>> is ppp0, but that still doesn't tell me which NIC is ppp0
>> associated with.
>>
>>  - Jeff
>>
>
> for that you need 'ifconfig ppp0'
>
> - Andrew
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

eugeny gladkih
In reply to this post by Leo Razoumov
On 13.02.2011 8:43, Leo Razoumov wrote:
> On Sat, Feb 12, 2011 at 23:44, Thomas Harning Jr.<[hidden email]>  wrote:
>> Let alone a way to define "default network interface".  Or is there?
>> Say I have 2 NICs, which one is default?
>>
>
> The one which is associated with a default route is a default interface.

you may have even a dozen such routes

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Leo Razoumov
In reply to this post by Axel Kittenberger
On Sun, Feb 13, 2011 at 05:37, Axel Kittenberger <[hidden email]> wrote:

> MAC is someting ethernet specific, not every network interface has to
> have one. Correct me if I'm wrong, but why should a PPP-connection
> have a mac adress anyway? Its a point-to-point connection, no need to
> address something on Layer 2 in the OSI Modell where Mac belongs to.
>
> Also not every computer must have a "default network interface", what
> if you are not connected to the internet and thus not have a default
> route? Or you are part of the backbone? (unlikely but possible :-)
>
> I wonder what the usecase is that warrents wanting to know "mac of the
> default network interface"?
>

I do not think that there is a universal definition of the "default
NIC interface" because its meaning depends on interpretation of the
word 'default' in this context. For the sake of sending/receiving IP
packets it is natural to assume 'default' being associated with a
default route.

On the other hand, for the sake of unique machine identification (e.g.
proprietary license code generation)  you might consider the first
Ethernet MAC.  Do 'ifconfig -a' if on UNIX and pick the NIC you like.

--Leo--

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Thomas Harning Jr.
For license generation, on OSX you have a UUID that is available and
shouldn't change (if it does somehow, itunes, for example, breaks
IIRR)

On windows you could abuse CryptProtectData since it is supposed to
protect data in a permachine manner... You can uniquely identify a
mach using that.

For linux... You'd want to determine how to identify a machine... NICs
can move, hard drives replaced, motherboards replaced,... What
constitutes a new machine?  Trying to use the windows activation
"algorithm" of generating an ID that can still be matched if a few
components change, but rquire reactivation beyond that.

Universal license management would require a special library to
support machine identification.  I could probably assist or take on
such a task if there is a need in the lua community.  Would prbably
dev in a plain c library than wrap in lua to make it the most useful
tool.

On 2/13/11, Leo Razoumov <[hidden email]> wrote:

> On Sun, Feb 13, 2011 at 05:37, Axel Kittenberger <[hidden email]> wrote:
>> MAC is someting ethernet specific, not every network interface has to
>> have one. Correct me if I'm wrong, but why should a PPP-connection
>> have a mac adress anyway? Its a point-to-point connection, no need to
>> address something on Layer 2 in the OSI Modell where Mac belongs to.
>>
>> Also not every computer must have a "default network interface", what
>> if you are not connected to the internet and thus not have a default
>> route? Or you are part of the backbone? (unlikely but possible :-)
>>
>> I wonder what the usecase is that warrents wanting to know "mac of the
>> default network interface"?
>>
>
> I do not think that there is a universal definition of the "default
> NIC interface" because its meaning depends on interpretation of the
> word 'default' in this context. For the sake of sending/receiving IP
> packets it is natural to assume 'default' being associated with a
> default route.
>
> On the other hand, for the sake of unique machine identification (e.g.
> proprietary license code generation)  you might consider the first
> Ethernet MAC.  Do 'ifconfig -a' if on UNIX and pick the NIC you like.
>
> --Leo--
>
>


--
Thomas Harning Jr.

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Jeff Pohlmeyer
In reply to this post by Andrew Cannon
Andrew Cannon wrote:

> Jeff Pohlmeyer wrote:

>> I am using pppoe on my machine and "route" tells me 0.0.0.0
>> is ppp0, but that still doesn't tell me which NIC is ppp0
>> associated with.

> for that you need 'ifconfig ppp0'

That still doesn't tell me which NIC  the ppp0 is associated with.

 - Jeff

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Javier Guerra Giraldez
On Sun, Feb 13, 2011 at 9:16 AM, Jeff Pohlmeyer
<[hidden email]> wrote:
> That still doesn't tell me which NIC  the ppp0 is associated with.

/dev/TTYS0 ?
COM1 ?

--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Jon Smirl
In reply to this post by Thomas Harning Jr.
I'm not doing licensing, instead I have multiple embedded devices that
are identical except for the MAC address. I'm trying to identify the
device. The devices are Linux based so I can write some C code to the
MAC address. I was trying to avoid the C code and the corresponding
build/install complications.

    struct ifreq ifinfo;
    strcpy(ifinfo.ifr_name, "eth0");
    int sd = socket(AF_INET, SOCK_DGRAM, 0);
    int result = ioctl(sd, SIOCGIFHWADDR, &ifinfo);
    close(sd);

    if ((result == 0) && (ifinfo.ifr_hwaddr.sa_family == 1)) {
        memcpy(mac_addr, ifinfo.ifr_hwaddr.sa_data, IFHWADDRLEN);
        return true;
    }
    return false;

On Sun, Feb 13, 2011 at 9:11 AM, Thomas Harning Jr. <[hidden email]> wrote:

> For license generation, on OSX you have a UUID that is available and
> shouldn't change (if it does somehow, itunes, for example, breaks
> IIRR)
>
> On windows you could abuse CryptProtectData since it is supposed to
> protect data in a permachine manner... You can uniquely identify a
> mach using that.
>
> For linux... You'd want to determine how to identify a machine... NICs
> can move, hard drives replaced, motherboards replaced,... What
> constitutes a new machine?  Trying to use the windows activation
> "algorithm" of generating an ID that can still be matched if a few
> components change, but rquire reactivation beyond that.
>
> Universal license management would require a special library to
> support machine identification.  I could probably assist or take on
> such a task if there is a need in the lua community.  Would prbably
> dev in a plain c library than wrap in lua to make it the most useful
> tool.
>
> On 2/13/11, Leo Razoumov <[hidden email]> wrote:
>> On Sun, Feb 13, 2011 at 05:37, Axel Kittenberger <[hidden email]> wrote:
>>> MAC is someting ethernet specific, not every network interface has to
>>> have one. Correct me if I'm wrong, but why should a PPP-connection
>>> have a mac adress anyway? Its a point-to-point connection, no need to
>>> address something on Layer 2 in the OSI Modell where Mac belongs to.
>>>
>>> Also not every computer must have a "default network interface", what
>>> if you are not connected to the internet and thus not have a default
>>> route? Or you are part of the backbone? (unlikely but possible :-)
>>>
>>> I wonder what the usecase is that warrents wanting to know "mac of the
>>> default network interface"?
>>>
>>
>> I do not think that there is a universal definition of the "default
>> NIC interface" because its meaning depends on interpretation of the
>> word 'default' in this context. For the sake of sending/receiving IP
>> packets it is natural to assume 'default' being associated with a
>> default route.
>>
>> On the other hand, for the sake of unique machine identification (e.g.
>> proprietary license code generation)  you might consider the first
>> Ethernet MAC.  Do 'ifconfig -a' if on UNIX and pick the NIC you like.
>>
>> --Leo--
>>
>>
>
>
> --
> Thomas Harning Jr.
>
>



--
Jon Smirl
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Jeff Pohlmeyer
In reply to this post by Javier Guerra Giraldez
On Sun, Feb 13, 2011 at 8:48 AM, Javier Guerra Giraldez wrote:
> On Sun, Feb 13, 2011 at 9:16 AM, Jeff Pohlmeyer wrote:

>> That still doesn't tell me which NIC  the ppp0 is associated with.

> /dev/TTYS0 ?
> COM1 ?

In my case the correct answer is eth1.

I know that because that's how I set it up in /etc/ppp/peers/provider.

But I thought the original question was how to find such information
from Lua, and my point was that parsing the output of route and/or
ifconfig might not always give the MAC address.


- Jeff

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Javier Guerra Giraldez
On Sun, Feb 13, 2011 at 7:14 PM, Jeff Pohlmeyer
<[hidden email]> wrote:
>>> That still doesn't tell me which NIC  the ppp0 is associated with.
>
>> /dev/TTYS0 ?
>> COM1 ?
>
> In my case the correct answer is eth1.

my point was that some IP devices might not be associated with a NIC.
in PPP case, it could be a serial port, for TUN devices, it could not
even be any hardware

--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Michal Kolodziejczyk-3
In reply to this post by Jon Smirl
On 13.02.2011 18:13, [hidden email] wrote:
> I'm not doing licensing, instead I have multiple embedded devices that
> are identical except for the MAC address. I'm trying to identify the
> device. The devices are Linux based so I can write some C code to the
> MAC address. I was trying to avoid the C code and the corresponding
> build/install complications.

Try nixio:
http://dev.luci.midlink.org/nixio/doc/modules/nixio.html#nixio.getifaddrs

Regards,
miko

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Petr Štetiar
In reply to this post by Jon Smirl
[hidden email] <[hidden email]> [2011-02-13 12:13:38]:

> I'm not doing licensing, instead I have multiple embedded devices that
> are identical except for the MAC address. I'm trying to identify the
> device. The devices are Linux based so I can write some C code to the
> MAC address. I was trying to avoid the C code and the corresponding
> build/install complications.

What kind of embedded device? Some of the CPUs/SOCs do have unique serial
number or some kind of that.

-- ynezz

Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

jose.camacho
In reply to this post by Jon Smirl

Hi everyone,

I follow the list since a while, but this is my first contribution. Thanks everyone for your support

Regarding the MAC address question, we also work with embedded Linux and what we do in such szenarios, is calling the OS interface functions using os.execute and shell commands.
Output will be save in a file and then, with strings parsed. The same functionality is used for reading process IDs, network usage, etc, and it is not *so* slow because we dump the information into a file in a Ramdisk.

For dumping the MAC Address, call os.execute ('ifconfig | grep HWaddr > [FILENAME]'). Then use io.open, read, close to get the info from the file into a lua string, then os.remove (to delete the file) and strings functions find (search for 'HWaddr ') and sub to extract the MAC info

Hope it helps

Regards,

José

> > I'm not doing licensing, instead I have multiple embedded devices that
> > are identical except for the MAC address. I'm trying to identify the
> > device. The devices are Linux based so I can write some C code to the
> > MAC address. I was trying to avoid the C code and the corresponding
> > build/install complications.
>
> Try nixio:
> http://dev.luci.midlink.org/nixio/doc/modules/nixio.html#nixio.getifaddrs
>
> Regards,
> miko
>
Reply | Threaded
Open this post in threaded view
|

RE: MAC Address

Cuero Bugot-2
> For dumping the MAC Address, call os.execute ('ifconfig | grep HWaddr > [FILENAME]'). Then use io.open,
> read, close to get the > info from the file into a lua string, then os.remove (to delete the file) and
> strings functions find (search for 'HWaddr ')  and sub to extract the MAC info

You could also use a more straight forward way (not using a temporary file):

local f = io.popen('ifconfig')
local t = f:read()
f:close()
local mac = t:match("HWaddr ([%:%x]*)")


Reply | Threaded
Open this post in threaded view
|

Re: MAC Address

Jon Smirl
This was the easiest one I found:

io.input("/sys/class/net/eth0/address")
t = io.read("*line")

These are embedded Linux devices so the network is always eth0.

--
Jon Smirl
[hidden email]