Exemplo n.º 1
0
    def get_nics_w32():
        # Return a list of nics found in the system
        ret = []

        w = Computer.get_wmi_connection()
        ifaces = w.Win32_NetworkAdapter()

        for iface in ifaces:
            attribs = NetworkDevices.get_attributes(iface)

            nic_name = iface.Name
            #dev_id = objItem.NetConnectionID
            nic_network_name = iface.NetConnectionID  # DeviceID?
            nic_if_index = iface.InterfaceIndex
            nic_ip_addresses = NetworkDevices.get_ip_addresses_for_device(
                nic_if_index)
            #iface.NetworkAddresses  # Default subnet?
            # OK if on
            nic_connected = iface.NetEnabled  # iface.MediaConnnectState # objItem.Status
            nic_enabled = iface.ConfigManagerErrorCode

            ret.append(
                (nic_name, nic_network_name, nic_ip_addresses, nic_connected,
                 nic_enabled, attribs, iface, nic_if_index))

        return ret
Exemplo n.º 2
0
    def scan_com_ports():
        # TODO - Need Debug
        # Use WMI to pull a list of com ports
        w = Computer.get_wmi_connection()

        p("Scanning USB/Serial COM Ports...")

        # Scan for PNP Devices that are ports
        for port in w.Win32_PNPEntity(PNPClass="Ports"):
            p("PNP COM Port Found: " + str(port.name))
            if port.Status == "OK":
                # Port is on and working - turn it off
                p("COM Port " + str(port.Caption) + " is on - disabling...")
                try:
                    port.Disable()
                except Exception as ex:
                    p("ERROR!!! " + str(ex))
            else:
                p("COM Port " + str(port.Caption) + " is off...")

        # Scan for Serial devices (may not be PNP)
        for port in w.Win32_SerialPort():
            print("Serial Port Found: " + str(port.name))
            if port.Status == "OK":
                p("Serial Port " + str(port.Caption) + " is on - disabling...")
                try:
                    port.Disable()
                except Exception as ex:
                    p("ERROR!!! " + str(ex))
            else:
                p("Serial Port " + str(port.Caption) + " is off...")

        return
Exemplo n.º 3
0
    def get_nic_by_interface_index(interface_index):
        # Find the nic in question
        ret = None

        w = Computer.get_wmi_connection()
        ifaces = w.Win32_NetworkAdapter(InterfaceIndex=interface_index)
        for iface in ifaces:
            ret = iface

        return ret
Exemplo n.º 4
0
    def disable_nic(interface_index):
        #w = wmi.WMI(namespace="StandardCimv2")
        w = Computer.get_wmi_connection(namespace="StandardCimv2")

        ifaces = w.MSFT_NetAdapter(InterfaceIndex=interface_index)
        for iface in ifaces:
            out = ""
            iface.Disable(out)
            if out != "":
                p("OUTPUT: " + str(out))
            #iface.Lock()

        return True
Exemplo n.º 5
0
    def ensure_opeservice_running():
        ret = False

        w = Computer.get_wmi_connection()

        services = w.Win32_Service(Name="OPEService")
        found = False
        for service in services:
            found = True
            if service.state == "Running":
                ret = True
            else:
                p("}}rbOPEService not in running state! " + str(service.state) + \
                    "\nTry rebooting and check again}}xx")

        if not found:
            p("}}rbOPEService not installed! - Try running credential again!}}xx")                
        return ret
Exemplo n.º 6
0
    def get_ip_addresses_for_device(interface_index):
        # Build the cache of addresses
        if NetworkDevices._NIC_CONFIGURATION_CACHE is None:
            # Get the list of configurations for ALL nics.
            w = Computer.get_wmi_connection()
            net_configs = w.Win32_NetworkAdapterConfiguration()
            NetworkDevices._NIC_CONFIGURATION_CACHE = dict()
            for c in net_configs:
                i = c.InterfaceIndex
                if not i in NetworkDevices._NIC_CONFIGURATION_CACHE:
                    NetworkDevices._NIC_CONFIGURATION_CACHE[i] = []
                if c.IPAddress is not None:
                    NetworkDevices._NIC_CONFIGURATION_CACHE[i] += c.IPAddress

        ip_addresses = []
        # Find the list of addresses for this adapter if present
        if interface_index in NetworkDevices._NIC_CONFIGURATION_CACHE:
            ip_addresses = NetworkDevices._NIC_CONFIGURATION_CACHE[
                interface_index]

        ret = ip_addresses

        return ret
Exemplo n.º 7
0
    def credential_laptop():
        
        # Are we running as admin w UAC??
        if not UserAccounts.is_uac_admin():
            p("}}rbNot Admin in UAC mode! - UAC Is required for credential process.}}xx")
            return False
        
        # Get computer info
        CredentialProcess.COMPUTER_INFO = Computer.get_machine_info(print_info=False)

        # Are we in a domain?
        if CredentialProcess.COMPUTER_INFO["cs_part_of_domain"] is True:
            p("}}rbSystem is doing to an Active Directory Domain - NOT SUPPORTED!\n" +
                "Please remove this from the domain as it might interfere with security settings.}}xx")
            return False
        
        # Are we using a proper edition win 10? (Home not supported, ed, pro, enterprise ok?)
        # OK - win 10 - pro, ed, enterprise
        # NOT OK - non win 10, win 10 home
        is_win10 = False
        is_win10_home = True
        os_caption = CredentialProcess.COMPUTER_INFO["os_caption"]
        if "Microsoft Windows 10" in os_caption:
            is_win10 = True
        if "Enterprise" in os_caption or "Professional" in os_caption or "Education" in os_caption:
            is_win10_home = False
        
        if is_win10 is not True:
            p("}}rbNOT RUNNING ON WINDOWS 10!!!\nThis software is designed to work win windows 10 ONLY!\n (Enterprise, Professional, or Education OK, Home edition NOT supported)}}xx")
            return False
        if is_win10_home is True:
            p("}}rbWIN10 HOME EDITION DETECTED!\nThis software is designed to work win windows 10 ONLY!\n (Enterprise, Professional, or Education OK, Home edition NOT supported)}}xx")
            return False

        # Disable guest account
        p("}}gnDisabling guest account}}xx", debug_level=2)
        UserAccounts.disable_guest_account()

        # Make sure folder exist and have proper permissions
        if not FolderPermissions.set_default_ope_folder_permissions():
            p("}}rbERROR - Unable to ensure folders are present and permissions are setup properly!}}xx")
            return False

        CredentialProcess.trust_ope_certs()

        # Disable all student accounts
        UserAccounts.disable_student_accounts()

        result = CredentialProcess.credential_input_verify_loop()
        if result is None:
            # Unable to verify?
            return False
        (student_user, student_name, student_password, admin_user, admin_password,
        canvas_access_token, canvas_url, smc_url) = result
        
        # - Create local student account
        p("}}gnCreating local student windows account...}}xx")
        if not UserAccounts.create_local_student_account(student_user, student_name, student_password):
            p("}}rbError setting up OPE Student Account}}xx\n " + str(ex))
            return False

        # - Setup admin user
        p("}}gnCreating local admin windows account...}}xx")
        try:
            UserAccounts.create_local_admin_account(admin_user, "OPE Laptop Admin", admin_password)
        except Exception as ex:
            p("}}rbError setting up OPE Laptop Admin Account}}xx\n " + str(ex))
        admin_password = ""

        # Store the credential information
        if not RegistrySettings.store_credential_info(canvas_access_token, canvas_url, smc_url,
            student_user, student_name, admin_user):
            p("}}rbError saving registry info!}}xx")
            return False
        
        # Create desktop shortcut
        #p("\n}}gnSetting up LMS App...}}xx")
        Computer.create_win_shortcut(
            lnk_path = "c:\\users\\public\\desktop\\OPE LMS.lnk",
            ico_path = "%programdata%\\ope\\Services\\lms\\logo_icon.ico",
            target_path = "%programdata%\\ope\\Services\\lms\\ope_lms.exe",
            description = "Offline LMS app for Open Prison Education project"
        )

        p("}}gnLocking machine - applying security settings...}}xx")
        if not CredentialProcess.lock_machine():
            p("}}rbERROR - Unable to lock machine after credentail!}}xx")
            return False
        
        return True
Exemplo n.º 8
0
    def get_nics_msft():

        # Return a list of nics found in the system
        ret = []

        w = Computer.get_wmi_connection(namespace="StandardCimv2")

        ifaces = w.MSFT_NetAdapter()

        for iface in ifaces:

            attribs = NetworkDevices.get_attributes(iface)

            # Note - we may have a #2 or #3 in the name
            nic_name = iface.InterfaceDescription
            #dev_id = objItem.NetConnectionID
            nic_id = iface.Name  # DeviceID?
            nic_network = iface.NetworkAddresses  # Default subnet?
            # (RO) 0-Unknown, 1-Connected, 2-Disconnected
            #nic_connected = iface.MediaConnectState # objItem.Status
            # 1-Up, 2-Down, 3-Testing, 4-Unknown, 5-Dormant, 6-NotPresent, 7-LowerLayerDown
            nic_connected = iface.InterfaceOperationalStatus
            # 1-Up, 2-Down, 3-Testing
            nic_enabled = iface.InterfaceAdminStatus

            ret.append((nic_name, nic_id, nic_network, nic_connected,
                        nic_enabled, attribs, iface))

        return ret

        # Need this so scanNics doesn't fail
        # NOTE - This happens once at the module level
        #pythoncom.CoInitialize()

        # The computer to inspect (localhost)
        strComputer = "."
        # Setup WMI connection
        objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
        objSWbemServices = objWMIService.ConnectServer(strComputer,
                                                       "root\cimv2")

        # Get the list of adapters
        #colItems = objSWbemServices.ExecQuery("Select * from Win32_NetworkAdapter")
        #colItems = objSWbemServices.ExecQuery("Select * from MSFT_NetAdapter")
        colItems = objSWbemServices.ExecQuery(
            "Select * from Win32_NetworkAdapterConfiguration")

        for objItem in colItems:
            # DEBUG - Dump attributes
            attribs = NetworkDevices.dump_attributes(objItem)

            # Note - we may have a #2 or #3 in the name
            nic_name = objItem.Name
            #dev_id = objItem.NetConnectionID
            nic_id = objItem.DeviceName  # DeviceID?
            nic_network = ""  # Default subnet?
            # (RO) 0-Unknown, 1-Connected, 2-Disconnected
            nic_connected = objItem.MediaConnnectState  # objItem.Status
            nic_enabled = False

            #net_enabled = objItem.NetEnabled
            # True if this is a physical adapter
            #connector_present = objItem.ConnectorPresent
            # (RO) Is this a hidden device - such as kernel debug driver?
            #device_hidden = objItem.Hidden
            # (RO) 1-Up, 2-Down, 3-Testing - Admin status?
            #admin_status = objItem.InterfaceAdminStatus
            # Unique name assigned during installatin?
            #interface_description = objItem.InterfaceDescription
            # Current operation status 1-Up, 2-Down, 3-Testing, 4-Unknown, 5-Dormant, 6-NotPresent, 7-LowerLayerDown
            #interface_operation_status = objItem.InterfaceOperationStatus
            # What kind of adapter is it?
            # 0-Unknown, 1-Other, 2-Ethernet, 3-IB, 4-FC, 5-FDDI, 6-ATM, 7-TokenRing, 8-FrameRelay, 9-Infrared
            # 10-BlueTooth, 11-WirelessLan,
            #link_technology = objItem.LinkTechnology

            # Media connected state (plugged in?)
            # 0-Unknown, 1-Connected, 2-Disconnected
            #media_connect_state = objeItem.MediaConnnectState

            # Can this adapter be removed by the user?
            #not_user_removable = objItem.NotUserRemovable

            nic_addresses = objItem.NetworkAddresses
            if nic_addresses:
                for a in nic_addresses:
                    # print("Network Address " + str(a))
                    ip_network += a

            ret.append((nic_name, nic_id, nic_network, nic_connected,
                        nic_enabled, attribs, iface))

        # Cleanup
        #pythoncom.CoUninitialize()

        return ret