[Pythonmac-SIG] Getting Sharing name of the Macintosh via Python?

David Hughes dfh at forestfield.co.uk
Thu Aug 4 09:14:00 CEST 2005


> *From:* "Schollnick, Benjamin" <Benjamin.Schollnick at xerox.com>
> *To:* <pythonmac-sig at python.org>
> *Date:* Wed, 3 Aug 2005 15:21:53 -0400
> 
> Anyone have any idea on how to get the Machine Name from the Sharing
> Preference pane?

import os
def  get_system_info():
    """ Use system_profiler command to return a dict of
        information about system
    """
    info_dict = {'systemversion': None,
                 'kernelversion': None,
                 'bootvolume': None,
                 'computername': None,
                 'username': None }
    command =  'system_profiler SPSoftwareDataType'
    fo = os.popen(command, 'r')
    for line in fo.readlines():
        ilist =  line[:-1].split(':')
        if len(ilist) >= 2:
            for key in info_dict:
                if key == ilist[0].replace(' ','').lower():
                    info_dict[key] = ilist[1]
    return info_dict
print repr(get_system_info())

Regards,

David Hughes
Forestfield Software
www.foresoft.co.uk


More information about the Pythonmac-SIG mailing list