[Tutor] How can I get the hostid of a computer?

Lance lbrannma@cablespeed.com
Sat, 19 Oct 2002 16:19:46 -0700


Thanks Magnus,

That worked great for me... I'm running XP.

Lance

----- Original Message -----
From: "Magnus Lycka" <magnus@thinkware.se>
To: "Lance" <lbrannma@cablespeed.com>; "Tutor" <tutor@python.org>
Sent: Saturday, October 19, 2002 1:53 PM
Subject: Re: [Tutor] How can I get the hostid of a computer?


At 11:02 2002-10-19 -0700, Lance wrote:
>I must be referring to the MacID, the CPU specific identifier on which
>licensing managers are based.

As I told you, I don't think there is any OS independent
way, so we can't really help you unless you tell what OS
you use.

If you by MacID mean MAC address, or Media Access Control
address, i.e. the hardware address in the network card,
this could work on Win 2000 for instance. The solution on
unix/linux is very similar. Please note that some machines
have several network cards (or none) which makes life more
difficult.

 >>> import os, re
 >>> pattern = re.compile(r'\w\w-\w\w-\w\w-\w\w-\w\w-\w\w')
 >>> text = os.popen('ipconfig /all').read()
 >>> m = pattern.search(text)
 >>> m.group(0)
'00-01-02-E0-FF-FF'


--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se