<commit_before># -*- coding: utf-8 -*-
'''
Scan a netmask or ipaddr for open ssh ports
'''
from __future__ import absolute_import

# Import python libs
import socket

# Import salt libs
import salt.ext.ipaddr


def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    rmatcher = RosterMatcher(tgt, tgt_type)
    return rmatcher.targets()


class RosterMatcher(object):
    '''
    Matcher for the roster data structure
    '''
    def __init__(self, tgt, tgt_type):
        self.tgt = tgt
        self.tgt_type = tgt_type

    def targets(self):
        '''
        Return ip addrs based on netmask, sitting in the "glob" spot because
        it is the default
        '''
        addrs = ()
        ret = {}
        try:
            salt.ext.ipaddr.IPAddress(self.tgt)
            addrs = [self.tgt]
        except ValueError:
            try:
                addrs = salt.ext.ipaddr.IPNetwork(self.tgt).iterhosts()
            except ValueError:
                pass
        for addr in addrs:
            addr = str(addr)
            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.settimeout(0.01)
                sock.connect((addr, 22))
                sock.shutdown(socket.SHUT_RDWR)
                sock.close()
                ret[addr] = {'host': addr}
            except socket.error:
                pass
        return ret<commit_msg>Utilize the new configuration options for ssh scan roster<commit_after># -*- coding: utf-8 -*-
'''
Scan a netmask or ipaddr for open ssh ports
'''
from __future__ import absolute_import

# Import python libs
import socket

# Import salt libs
import salt.ext.ipaddr


def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    rmatcher = RosterMatcher(tgt, tgt_type)
    return rmatcher.targets()


class RosterMatcher(object):
    '''
    Matcher for the roster data structure
    '''
    def __init__(self, tgt, tgt_type):
        self.tgt = tgt
        self.tgt_type = tgt_type

    def targets(self):
        '''
        Return ip addrs based on netmask, sitting in the "glob" spot because
        it is the default
        '''
        addrs = ()
        ret = {}
        ports = __opts__['ssh_scan_ports']
        if not isinstance(ports, list):
            # Comma-separate list of integers
            ports = list(map(int, str(ports).split(',')))
        try:
            salt.ext.ipaddr.IPAddress(self.tgt)
            addrs = [self.tgt]
        except ValueError:
            try:
                addrs = salt.ext.ipaddr.IPNetwork(self.tgt).iterhosts()
            except ValueError:
                pass
        for addr in addrs:
            addr = str(addr)
            for port in ports:
                try:
                    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    sock.settimeout(__opts__['ssh_scan_timeout'])
                    sock.connect((addr, port))
                    sock.shutdown(socket.SHUT_RDWR)
                    sock.close()
                    ret[addr] = {'host': addr, 'port': port }
                except socket.error:
                    pass
        return ret
{'fraction_non_alphanumeric': 0.09759715218036191, 'fraction_numerical': 0.0020765351527736575, 'mean_word_length': 1.7481662591687042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1505812', 'n_tokens_mistral': 1000, 'n_tokens_neox': 953, 'n_words': 270}