environment fingerprint

Jabba Laci jabba.laci at gmail.com
Wed Jan 30 00:33:12 CET 2013


Thanks for the tip. I came up with the solution below. For my purposes
the short fingerprint is enough.



import platform as p
import uuid
import hashlib

def get_fingerprint(md5=False):
Fingerprint of the current operating system/platform.

If md5 is True, a digital fingerprint is returned.
    sb = []
    sb.append(str(uuid.getnode())) # MAC address
    text = '#'.join(sb)
    if md5:
        md5 = hashlib.md5()
        return md5.hexdigest()
        return text

def get_short_fingerprint(length=6):
A short digital fingerprint of the current operating system/platform.

Length should be at least 6 characters.
    assert 6 <= length <= 32
    return get_fingerprint(md5=True)[-length:]

On Tue, Jan 29, 2013 at 2:43 PM, Andrew Berg <bahamutzero8825 at gmail.com> wrote:
> On 2013.01.29 07:18, Jabba Laci wrote:
>> Hi,
>> I have a script that I want to run in different environments: on
>> Linux, on Windows, on my home machine, at my workplace, in virtualbox,
>> etc. In each environment I want to use different configurations. For
>> instance the temp. directory on Linux would be /tmp, on Windows
>> c:\temp, etc. When the script starts, I want to test the environment
>> and load the corresponding config. settings. How to get an
>> OS-independent fingerprint of the environment?
> http://docs.python.org/3.3/library/platform.html
> http://docs.python.org/3.3/library/os.html#os.environ
> --
> CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE
> --
> http://mail.python.org/mailman/listinfo/python-list

More information about the Python-list mailing list