<commit_before>#    File:    Asset.py
#    Author:  <NAME>
#    Date:    6/15/2015
#
#    Purpose: LLNMS Asset Utilities.
#
__author__ = '<NAME>'


#  System Libraries
import glob, logging, os, re
import xml.etree.ElementTree as ET

#  Python Libraries
import Scanner, Globals, utility.XML_Utilities


# ----------------------------- #
# -       Asset Address       - #
# ----------------------------- #
class AssetAddress(object):

    #  IP Type
    ip_type = None

    #  IP Value
    ip_value = None

    #  Remote Access
    remote_access = None

    # --------------------------- #
    # -       Constructor       - #
    # --------------------------- #
    def __init__(self, ip_type=None,
                       ip_value=None,
                       remote_access = [False, {}]):

        #  Set the type
        self.ip_type = ip_type

        #  Set the value
        self.ip_value = ip_value

        #  Set the remote access
        self.remote_access = remote_access


    # ------------------------------------------------- #
    # -       Check if the AddressType is Valid       - #
    # ------------------------------------------------- #
    def Is_Valid(self):

        #  Check the ip type
        if IP_Address_Type.Is_Valid(self.ip_type):
            return False

        #  Otherwise true
        return True

    # ------------------------------------- #
    # -       Print to list format        - #
    # ------------------------------------- #
    def To_List_String(self):

        #  Output
        output = utility.Network_Utilities.IP_Address_Type().To_String(self.ip_type) + ' ' + self.ip_value

        return output

    # -------------------------------------- #
    # -       Print to Pretty Format       - #
    # -------------------------------------- #
    def To_Pretty_String(self, index = None):

        #  Output
        index_str = ''
        if index is not None:
            index_str = 'Index ' + str(index)
        output  = '     Address : ' + index_str + '\n'
        output += '        IP Address Type: ' + utility.Network_Utilities.IP_Address_Type().To_String(self.ip_type) + '\n'
        output += '        Address Value  : ' + self.ip_value + '\n'
        output += '        Remote Access\n'
        output += '                 Enabled : ' + str(self.remote_access[0]) + '\n'
        output += '               Driver-ID : ' + str(self.remote_access[1]['remote-driver']) + '\n'
        output += '                username : ' + str(self.remote_access[1]['login-username']) + '\n'
        output += '\n'

        return output

# ---------------------------- #
# -       Asset Class        - #
# ---------------------------- #
class Asset(object):

    #  Hostname
    hostname = None

    #  Address
    address_list = []

    #  Description
    description = None

    #  Registered scanners
    registered_scanners = []

    #  Filename
    filename = None

    #  Hostname Regex
    hostname_regex = re.compile(Globals.LLNMS_HOSTNAME_REGEX_PATTERN)

    # --------------------------- #
    # -       Constructor       - #<commit_msg>Working on asset remote access.<commit_after>#    File:    Asset.py
#    Author:  <NAME>
#    Date:    6/15/2015
#
#    Purpose: LLNMS Asset Utilities.
#
__author__ = '<NAME>'


#  System Libraries
import glob, logging, os, re
import xml.etree.ElementTree as ET

#  Python Libraries
import Scanner, Globals, utility.XML_Utilities


# ----------------------------------------- #
# -     Remote Access Asset Attribute     - #
# ----------------------------------------- #
class AssetRemoteAccessState(object):


    # --------------------------- #
    # -       Constructor       - #
    # --------------------------- #
    def __init__( self, enabled = False,
                        attributes = {} ):

        
        #  Set the enabled flag
        self.enabled = enabled

        #  Set the attribute list
        self.attributes = attributes



# ----------------------------- #
# -       Asset Address       - #
# ----------------------------- #
class AssetAddress(object):

    #  IP Type
    ip_type = None

    #  IP Value
    ip_value = None

    #  Remote Access
    remote_access = None

    # --------------------------- #
    # -       Constructor       - #
    # --------------------------- #
    def __init__(self, ip_type=None,
                       ip_value=None,
                       remote_access = None):

        #  Set the type
        self.ip_type = ip_type

        #  Set the value
        self.ip_value = ip_value

        #  Set the remote access
        if remote_access is None:
            self.remote_access = AssetRemoteAccessState()
        else:
            self.remote_access = remote_access


    # ------------------------------------------------- #
    # -       Check if the AddressType is Valid       - #
    # ------------------------------------------------- #
    def Is_Valid(self):

        #  Check the ip type
        if IP_Address_Type.Is_Valid(self.ip_type):
            return False

        #  Otherwise true
        return True

    # ------------------------------------- #
    # -       Print to list format        - #
    # ------------------------------------- #
    def To_List_String(self):

        #  Output
        output = utility.Network_Utilities.IP_Address_Type().To_String(self.ip_type) + ' ' + self.ip_value

        return output

    # -------------------------------------- #
    # -       Print to Pretty Format       - #
    # -------------------------------------- #
    def To_Pretty_String(self, index = None):

        #  Output
        index_str = ''
        if index is not None:
            index_str = 'Index ' + str(index)
        output  = '     Address : ' + index_str + '\n'
        output += '        IP Address Type: ' + utility.Network_Utilities.IP_Address_Type().To_String(self.ip_type) + '\n'
        output += '        Address Value  : ' + self.ip_value + '\n'
        output += '        Remote Access\n'
        output += '                 Enabled : ' + str(self.remote_access.enabled) + '\n'
        output += '               Driver-ID : ' + str(self.remote_access.attributes['remote-driver']) + '\n'
        output += '                username : ' + str(self.remote_access.attributes['login-username']) + '\n'
        output += '\n'

        return output

# ---------------------------- #
# -       Asset Class        - #
# ---------------------------- #
class Asset(object):

    #  Hostname
    hostname = None

    #  Address
    address_list = []

    #  Description
    description = None

    #  Registered scanners
    registered_scanners = []

    #  Filename
    filename = None

    #  Hostname Regex
    hostname_regex = re.compile(Globals.LLNMS_HOSTNAME_REGEX_PATTERN)

    # --------------------------- #
    # -       Constructor       - #
{'fraction_non_alphanumeric': 0.2392575270388775, 'fraction_numerical': 0.0024846536100555394, 'mean_word_length': 1.08373934226553, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7295913', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1768, 'n_words': 388}