import os
import platform
import ctypes
from subprocess import PIPE, Popen, STDOUT
import re

def ecmd(command):
    class disable_file_system_redirection:
        _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
        _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
        def __enter__(self):
            self.old_value = ctypes.c_long()
            self.success = self._disable(ctypes.byref(self.old_value))
        def __exit__(self, type, value, traceback):
            if self.success:
                self._revert(self.old_value)

    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = obj.communicate()
    ret=obj.returncode
    if ret==0:
        if out:
            return out.strip()
        else:
            return ret
    else:
        if err:
            return err.strip()
        else:
            return ret

if platform.system() == 'Windows':
    print "Model of Device:  Windows", platform.release()
    print "\n"
    print ecmd(r'wmic bios get serialnumber')
    print "\n"
    cmd= ecmd(r'systeminfo')
    ser=re.findall('Product ID:(.*)',cmd)
    product_id=''.join(ser).strip().replace(",",'')
    print "Product ID",product_id
    print ecmd(r'wmic computersystem get model,name,manufacturer,systemtype')
    print "\n"
    print "WLAN MAC Adress: ",ecmd(r'getmac').split()[6]
	
elif platform.system() == 'Mac':
    print "Model of Device:  Mac", platform.release()
    serial_num = Popen('ioreg -l | grep IOPlatformSerialNumber',stdin=PIPE,stdout=PIPE,shell=True)
    print "Serial Number: ",serial_num.communicate()
    obj=Popen('ifconfig',stdin=PIPE,stdout=PIPE,shell=True)
    print obj.communicate()[0]
