Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determining Ethernet HW Address

655 views
Skip to first unread message

Jerome Chan

unread,
Mar 26, 2000, 3:00:00 AM3/26/00
to
Is there a portable way of determining the Ethernet HW Address?

Jim Nicholson

unread,
Mar 27, 2000, 3:00:00 AM3/27/00
to
Jerome Chan wrote:
> Is there a portable way of determining the Ethernet HW Address?

I don't know the answer to this, but which Ethernet Interface were you
thinking of - remember a machine can have multiple ethernet cards, PPP
dialup connections etc. So if you were going to look for the MAC address
for _an_ ethernet interface, you would need to specify _which_ ethernet
interface you wanted, and AFAIK there is no standard way of referring to
them.

Linux calls them
eth0, eth1, eth2 etc. for ethernet cards
ppp0, ppp1 etc for dial-up connections over a modem

IIRC Solaris calls ethernet cards le0, le1 etc. (thats "ell ee zero" etc.)

goodness knows how WinDoze refers to them.

Jim

Darrell

unread,
Mar 27, 2000, 3:00:00 AM3/27/00
to
"Jerome Chan" <evil...@rocketmail.com> wrote in message

> Is there a portable way of determining the Ethernet HW Address?
>
For windows without using Win32 try parsing the output of ipconfig /all

--Darrell


Mark Hammond

unread,
Mar 28, 2000, 3:00:00 AM3/28/00
to
"Darrell" <dar...@dorb.com> wrote in message
news:dhSD4.7202$JE5....@typhoon.nyroc.rr.com...

I couldnt resist :-) In win32all-130 you will be able to use the
Netbios function:

from netbios import *
# code ported from "HOWTO: Get the MAC Address for an
Ethernet Adapter"
# MS KB ID: Q118623
ncb = NCB()
ncb.Command = NCBENUM
la_enum = LANA_ENUM()
ncb.Buffer = la_enum
rc = Netbios(ncb)
if rc != 0: raise RuntimeError, "Unexpected result %d" %
(rc,)
for i in range(la_enum.length):
ncb.Reset()
ncb.Command = NCBRESET
ncb.Lana_num = ord(la_enum.lana[i])
rc = Netbios(ncb)
if rc != 0: raise RuntimeError, "Unexpected result %d" %
(rc,)
ncb.Reset()
ncb.Command = NCBASTAT
ncb.Lana_num = ord(la_enum.lana[i])
ncb.Callname = "* "
adapter = ADAPTER_STATUS()
ncb.Buffer = adapter
Netbios(ncb)
print "Adapter address:",
for ch in adapter.adapter_address:
print "%02x" % (ord(ch),) ,
print

Yields on my dual-NIC server:
Adapter address: 00 a0 cc 54 22 2d
Adapter address: 00 40 05 6b fc ca

(both of which are correct :-)

Mark.

Randall Hopper

unread,
Mar 28, 2000, 3:00:00 AM3/28/00
to Jerome Chan
Jerome Chan:

|Is there a portable way of determining the Ethernet HW Address?

Which one? If your machine has multiple ethernet ports (e.g. multi-homed
host), you may have more than one...

--
Randall Hopper
aa...@yahoo.com


Jerome Chan

unread,
Mar 28, 2000, 3:00:00 AM3/28/00
to
In article <NJ0E4.5818$V56....@news-server.bigpond.net.au>, "Mark
Hammond" <mham...@skippinet.com.au> wrote:

> "Darrell" <dar...@dorb.com> wrote in message
> news:dhSD4.7202$JE5....@typhoon.nyroc.rr.com...
> > "Jerome Chan" <evil...@rocketmail.com> wrote in message

> > > Is there a portable way of determining the Ethernet HW
> Address?
> > >

The question had a portable section :P which was my main question. I've
need the ethernet hw address given an IP and the Python code runs on
Win32 and Linux... so...

David Arnold

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to pytho...@python.org
-->"Mark" == Mark Hammond <mham...@skippinet.com.au> writes:

Mark> I couldnt resist :-) In win32all-130 you will be able to use
Mark> the Netbios function:

this is a pretty common question. is it worth adding this to the os
module for 1.6? or maybe a different module?

it could be useful to have mappings between IP and MAC addresses too?


d


Erno Kuusela

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
>>>>> "Jerome" == Jerome Chan <evil...@rocketmail.com> writes:

Jerome> I've need the ethernet hw address given an IP and the
Jerome> Python code runs on Win32 and Linux... so...

there is no portable way of getting it even in C. i guess your best
bet would be parsing ifconfig output... but that too varies
between operating systems.

if you decide to write a module that knows how to do this on many
platforms, send me a copy :)

-- erno

Grant Edwards

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
On 29 Mar 2000 01:30:54 +0300, Erno Kuusela <er...@iki.fi> wrote:
>>>>>> "Jerome" == Jerome Chan <evil...@rocketmail.com> writes:
>
> Jerome> I've need the ethernet hw address given an IP and the
> Jerome> Python code runs on Win32 and Linux... so...
>
>there is no portable way of getting it even in C. i guess your best
>bet would be parsing ifconfig output... but that too varies
>between operating systems.

Mind if I ask why people want to do this?

The question of how to get the Ethernet address of an interface
seems to come up regularly in various newsgroups (it comes up
in the Linux groups regularly). I've been messing with
computers for 15 years and never needed to know an Ethernet
address in a program, so I'm curious...

--
Grant Edwards grante Yow! I'm having an
at EMOTIONAL OUTBURST!! But,
visi.com uh, WHY is there a WAFFLE
in my PAJAMA POCKET??

Jim Richardson

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
On Wed, 29 Mar 2000 01:24:02 GMT,
Grant Edwards, in the persona of <nob...@nowhere.nohow>,
brought forth the following words...:

>On 29 Mar 2000 01:30:54 +0300, Erno Kuusela <er...@iki.fi> wrote:
>>>>>>> "Jerome" == Jerome Chan <evil...@rocketmail.com> writes:
>>
>> Jerome> I've need the ethernet hw address given an IP and the
>> Jerome> Python code runs on Win32 and Linux... so...
>>
>>there is no portable way of getting it even in C. i guess your best
>>bet would be parsing ifconfig output... but that too varies
>>between operating systems.
>
>Mind if I ask why people want to do this?
>
>The question of how to get the Ethernet address of an interface
>seems to come up regularly in various newsgroups (it comes up
>in the Linux groups regularly). I've been messing with
>computers for 15 years and never needed to know an Ethernet
>address in a program, so I'm curious...
>
>--


I can't speak for others, but I have needed to pass data straight to the MAC
address, avoiding all networking layers, in order to test 10/100 base T
microwave units through-put in (relatively) long term, and to get BER numnbers
over several hours. But this is coming from data pipes orthogonal to
computers, so YMMV.

--
Jim Richardson
Anarchist, pagan and proud of it
WWW.eskimo.com/~warlock
Linux, because life's too short for a buggy OS.


Emile van Sebille

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to pytho...@python.org
The MAC ID has been used for licensing as a form
of cross platform GUID. Other applications that
require a similar unique identifier would probably
use it as well.

Emile van Sebille
em...@fenx.com
-------------------

Grant Edwards

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
In article <025f01bf9971$ffa1a100$01ff...@worldnet.att.net>, Emile van Sebille wrote:

>The MAC ID has been used for licensing as a form of cross
>platform GUID. Other applications that require a similar
>unique identifier would probably use it as well.

So if my Ethernet board dies and has to be replaced, my
applications refuse to run? That sure sucks rocks.

I'm still pissed off at Applix from the time their office suite
refused to run after I replaced my machine with a newer,
faster, better model. Applix refused to help unless I paid for
two years of support.

I'd probably be using Applix today instead of Word Perfect and
StarOffice if it wasn't for that whole node-locked licensing
debacle.

--
Grant Edwards grante Yow! FUN is never having
at to say you're SUSHI!!
visi.com

Cliff Crawford

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
* Jerome Chan bilang:
|
| The question had a portable section :P which was my main question. I've
| need the ethernet hw address given an IP and the Python code runs on
| Win32 and Linux... so...

So are you trying to find the MAC address of the machine you're on, or
another machine on the network? If it's a different machine, then
under Linux I would parse the output of arp -a, or try pinging the
machine in question and then use a packet sniffer to grab the ARP
packets. I have >no< idea how to do this in Windows, though. :)


--
cliff crawford -><- http://www.people.cornell.edu/pages/cjc26/
icq 68165166
"IS I yes wardrobe yield [the] evaluation." member of A.H.M.A.D.

pehr anderson

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
I would *really* appreciate this feature being added to the 'os' module.
This is really important for a lot of everyday, practical applications.
-pehr

Randall Hopper

unread,
Mar 30, 2000, 3:00:00 AM3/30/00
to pehr anderson
pehr anderson:

|David Arnold wrote:
|> this is a pretty common question. is it worth adding this to the os
|> module for 1.6? or maybe a different module?
|>
|> it could be useful to have mappings between IP and MAC addresses too?
|
|I would *really* appreciate this feature being added to the 'os' module.
|This is really important for a lot of everyday, practical applications.

If it could be cross-platform and generic, cool. In other words, handles
multiple network cards (potentially multiple MAC addresses) per box,
handles IPv6 stacks (long IPs), handles boxes running non-IP stacks such as
ATM, deals with boxes that store the MAC address in NVRAM and share it for
all network interfaces ...except for FDDI (Sun), etc.

Given the varied ways of obtaining this information on differenet
platforms, this sounds like a maintenance nightmare just waiting to happen.

Even then, a problem is that on some boxes you can't determine the MAC
addresses without root priviledge and/or having pre-configured your OS a
certain way (e.g. built your kernel to enable specific networking options).

--
Randall Hopper
aa...@yahoo.com


Grant Edwards

unread,
Mar 30, 2000, 3:00:00 AM3/30/00
to
In article <38E291DD...@pehr.net>, pehr anderson wrote:

>I would *really* appreciate this feature being added to the 'os' module.
>This is really important for a lot of everyday, practical applications.

I'm still curious of what use the Ethernet address is to an
application?

If "really important for everyday, practical applications"
means "useful for node-locking user licenses", then I'd vote no
(not that anybody asked for my vote), since I think node locked
licenses are evil.

--
Grant Edwards grante Yow! FOOLED you! Absorb
at EGO SHATTERING impulse
visi.com rays, polyester poltroon!!

Grant Edwards

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to
In article <38e4e401...@news.btx.dtag.de>, Stefan Franke wrote:
>On Thu, 30 Mar 2000 20:54:23 GMT, grant@nowhere. (Grant Edwards)
>wrote:

>
>>I'm still curious of what use the Ethernet address is to an
>>application?
>
>Perhaps globally unique random number generation?
>

My Ethernet addresses aren't random -- they're all quite predictable.
In fact, they read the same each time I check them. Not too useful for
random number generation.

--
Grant Edwards grante Yow! I am having a
at pleasant time!!
visi.com

Anthony J Wilkinson

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to Grant Edwards
On Fri, 31 Mar 2000, Grant Edwards wrote:

> In article <38e4e401...@news.btx.dtag.de>, Stefan Franke wrote:
> >On Thu, 30 Mar 2000 20:54:23 GMT, grant@nowhere. (Grant Edwards)
> >wrote:
> >
> >>I'm still curious of what use the Ethernet address is to an
> >>application?
> >
> >Perhaps globally unique random number generation?
> >
>
> My Ethernet addresses aren't random -- they're all quite predictable.
> In fact, they read the same each time I check them. Not too useful for
> random number generation.

But useful to give a different seed to a random function for each
different machine. Combine this with date/time and you have a very good
candidate for a globally unique number which will certainly improve
pseudo-random functions.

Random functions aren't really random - if you give them the same input
(seed) they will return the same output.

Regards,
Anthony

Grant Edwards

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to
In article <Pine.OSF.4.20.00033...@azure.dstc.edu.au>, Anthony J Wilkinson wrote:

>>>>I'm still curious of what use the Ethernet address is to an application?
>>>
>>>Perhaps globally unique random number generation?
>>
>> My Ethernet addresses aren't random -- they're all quite predictable.
>> In fact, they read the same each time I check them. Not too useful for
>> random number generation.
>
>But useful to give a different seed to a random function for each
>different machine.

But it's different in an utterly predictable and time-invariant way.

>Combine this with date/time and you have a very good candidate for a
>globally unique number which will certainly improve pseudo-random functions.

No, it won't improve a pseudo-random function. The pseudo-random function
will still have the same periodicity and correlation features (or whatever
the random-number experts call it). All you're doing is adding a constant
value to the seed. By adding the Ethernet address to the seed, you're just
starting at a different place in the sequence generated by the pseudo-random
number generator. And that "difference" is a constant!

If you've got a pseudo-random number generator that generates a lousy
sequence, then starting at a different place in the sequence isn't helping
anything:

Let's say your p-r sequence is:

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ....

As you can see, it has a cycle length of 10, so we'll pick a seed value of
(system_time_in_microseconds() % 10), and that value will determine where in
the cycle we start. [We're assuming we can measure system time with a
resolution of microseconds.]

Now let's modify the seed value with a constant (e.g. a number derived from
the Ethernet address, we'll assume that for a particular computer that comes
out to 4)

So now seed = (system_time_in_microseconds() + 4) % 10

That doesn't improve anything. The output is no more random than before. It
is no easier or harder to predict the output of the algorithm. You have
accomplished nothing by adding a constant value to the seed. In practice,
adding a _random_ value to the seed won't even improve anything unless the
seed was a constant to start with. For all practical purposes, the seed was
already random (generating a fairly random seed isn't all that hard).

While my example seems overly-simplivied, the same applies if you're using
a generator with a cycle length of 2^32.

>Random functions aren't really random - if you give them the same input
>(seed) they will return the same output.

And adding a constant (such as the Ethernet address) to that input doesn't
improve the "randomness of the output" it just changes it in an entirely
predictable and repeatable way. Adding a constant value to the seed
accomplished nothing.

You can't generate more or better randomness by shoving more constants (such
as an Ethernet address) into a function.

--
Grant Edwards grante Yow! I love ROCK 'N
at ROLL! I memorized the
visi.com all WORDS to "WIPE-OUT"
in1965!!

Steve Holden

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to
Grant Edwards wrote:
>
> In article <Pine.OSF.4.20.00033...@azure.dstc.edu.au>, Anthony J Wilkinson wrote:
>
> >>>>I'm still curious of what use the Ethernet address is to an application?
> >>>
> >>>Perhaps globally unique random number generation?
> >>
> >> My Ethernet addresses aren't random -- they're all quite predictable.
> >> In fact, they read the same each time I check them. Not too useful for
> >> random number generation.
> >
> >But useful to give a different seed to a random function for each
> >different machine.
>
> But it's different in an utterly predictable and time-invariant way.
>
> >Combine this with date/time and you have a very good candidate for a
> >globally unique number which will certainly improve pseudo-random functions.
>
> No, it won't improve a pseudo-random function. The pseudo-random function
> will still have the same periodicity and correlation features (or whatever
> the random-number experts call it). All you're doing is adding a constant
> value to the seed. By adding the Ethernet address to the seed, you're just
> starting at a different place in the sequence generated by the pseudo-random
> number generator. And that "difference" is a constant!
>
> [treatise on pseudo-random number generation]

>
> You can't generate more or better randomness by shoving more constants (such
> as an Ethernet address) into a function.
>
> --
> Grant Edwards grante Yow! I love ROCK 'N
> at ROLL! I memorized the
> visi.com all WORDS to "WIPE-OUT"
> in1965!!

Your remarks are correct, but perhaps not to the point.

I suspect that what was being suggested here was the use of the Ethernet
address in the creation of GUIs (globally-unique identifiers). For such
an identifier to be globally unique it requires two components.

One is a portion specific to the locale in which it is created, which
is what guarantees the global uniqueness. An Ethernet identifier would
do quite nicely for this purpose (although manufacturers have been known
to slip up and produce more than one interface with a particular MAC
address). Thus every GUI produced by a particular machine would have
a part of the GUI fixed.

The second is a once-only value from the locale: frequently this is a
derivative of the time, but the next number from a pseudo-random
sequence would do very well also. The seed for the sequence is not
really relevant here, the important thing is that each value should
be used only once.

regards
Steve
--
"Bulding information systems just because it's fun."
Steve Holden sho...@bellatlantic.net 703 716 7275

Fredrik Lundh

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to
Steve Holden <sho...@bellatlantic.net> wrote

> I suspect that what was being suggested here was the use of the Ethernet
> address in the creation of GUIs (globally-unique identifiers). For such
> an identifier to be globally unique it requires two components.

you mean GUID, I hope (or UUID, depending on
you who you ask)

> One is a portion specific to the locale in which it is created, which
> is what guarantees the global uniqueness. An Ethernet identifier would

> do quite nicely for this purpose.

only if you don't really care about privacy issues,
of course...

</F>

0 new messages