示例#1
0
    def get_ports(self, args):
        ports = []
        # Determine list of ports to use
        if args.port_list is None:
            if args.low_port is not None or args.high_port is not None:
                # Try using port low to high port range
                low = args.low_port
                high = args.high_port
                try:
                    if low > 0 and low < high:
                        ports = [i for i in range(low, high + 1)]
                except:
                    print('Specified port range invalid')
            else:
                # Use top 50 ports
                ports = get_top_50_ports()
        else:
            # Use user defined ports
            all_ports = get_all_ports()
            user_ports = read_file(args.port_list)

            # Create dataframe and append description of ports if available
            descriptions = [None for i in range(len(user_ports))]
            user_ports = [row['data'] for _, row in user_ports.iterrows()]
            ports = pd.DataFrame(np.column_stack([user_ports, descriptions]),
                                 columns=['port', 'description'])
            for _, row in ports.iterrows():
                new = all_ports.loc[all_ports['port'] == row['port']]
                if not new.empty:
                    row['description'] = new.iloc[0]['description']
                else:
                    row['description'] = 'none'

        # Return list of ports
        return ports
示例#2
0
def init_kbase():
    ''' Read hypernyms from knowledge base '''
    names = open_files(KBASE_PATH)
    kbase = {}

    for name in names:
        curr = name.split('/')[-1].split('.')[0]
        hypernyms = read_file(name, 'txt')
        kbase[curr] = hypernyms
    return kbase
示例#3
0
 def get_fv(cls, dates, labels, news, file_name):
     path = f'tmp/{file_name}.obj'
     try:
         filename = open_file(path)
         feature_vec = read_file(filename, 'obj')
     except Exception:
         type_ = file_name.split('_')[1]
         feature_vec = FeatureVector(dates, labels, news, type_)
         save_file(path, feature_vec)
     return feature_vec
示例#4
0
    def get_hosts(self, args):
        hosts = []

        # Append all provided hosts to list
        if args.host is not None:
            hosts.append(args.host)

        if args.cidr is not None:
            nw = ip_network(args.cidr)
            for ip in nw:
                hosts.append(str(ip))

        if args.ip_list is not None:
            data = read_file(args.ip_list)
            for _, row in data.iterrows():
                hosts.append(row['data'])

        # If no hosts are provided, use demo
        if len(hosts) == 0:
            hosts.append('scanme.nmap.org')

        return hosts
from utils.file_io import save_to_file, read_file

save_to_file("hi raghu how are u?", "data1.txt")
print(read_file("data1.txt"))