Re: environment fingerprint

Discussion in 'Python' started by Jabba Laci, Jan 29, 2013.

  1. Jabba Laci

    Jabba Laci Guest

    Hi,

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

    Laszlo

    ======

    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(p.node())
    sb.append(p.architecture()[0])
    sb.append(p.architecture()[1])
    sb.append(p.machine())
    sb.append(p.processor())
    sb.append(p.system())
    sb.append(str(uuid.getnode())) # MAC address
    text = '#'.join(sb)
    if md5:
    md5 = hashlib.md5()
    md5.update(text)
    return md5.hexdigest()
    else:
    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 <> 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
     
    Jabba Laci, Jan 29, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Javier Camacho

    Microsoft FingerPrint Reader

    Javier Camacho, Sep 16, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    5,534
    =?Utf-8?B?Sm9obg==?=
    Oct 21, 2005
  2. pvs
    Replies:
    10
    Views:
    1,114
  3. Jabba Laci

    environment fingerprint

    Jabba Laci, Jan 29, 2013, in forum: Python
    Replies:
    0
    Views:
    122
    Jabba Laci
    Jan 29, 2013
  4. Andrew Berg

    Re: environment fingerprint

    Andrew Berg, Jan 29, 2013, in forum: Python
    Replies:
    0
    Views:
    118
    Andrew Berg
    Jan 29, 2013
  5. Chris Angelico

    Re: environment fingerprint

    Chris Angelico, Jan 30, 2013, in forum: Python
    Replies:
    0
    Views:
    113
    Chris Angelico
    Jan 30, 2013
Loading...

Share This Page