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

Magnus Lycka magnus@thinkware.se
Sat, 19 Oct 2002 22:53:56 +0200


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 =3D re.compile(r'\w\w-\w\w-\w\w-\w\w-\w\w-\w\w')
 >>> text =3D os.popen('ipconfig /all').read()
 >>> m =3D pattern.search(text)
 >>> m.group(0)
'00-01-02-E0-FF-FF'


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se