<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import socket <EOL> import logging <EOL> import salt . utils . network <EOL> from salt . _compat import ipaddress <EOL> from salt . ext . six . moves import map <EOL> log = logging . getLogger ( __name__ ) <EOL> def targets ( tgt , tgt_type = '<STR_LIT>' , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> rmatcher = RosterMatcher ( tgt , tgt_type ) <EOL> return rmatcher . targets ( ) <EOL> class RosterMatcher ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , tgt , tgt_type ) : <EOL> self . tgt = tgt <EOL> self . tgt_type = tgt_type <EOL> def targets ( self ) : <EOL> '''<STR_LIT>''' <EOL> addrs = ( ) <EOL> ret = { } <EOL> ports = __opts__ [ '<STR_LIT>' ] <EOL> if not isinstance ( ports , list ) : <EOL> ports = list ( map ( int , str ( ports ) . split ( '<STR_LIT:U+002C>' ) ) ) <EOL> try : <EOL> addrs = [ ipaddress . ip_address ( self . tgt ) ] <EOL> except ValueError : <EOL> try : <EOL> addrs = ipaddress . ip_network ( self . tgt ) . hosts ( ) <EOL> except ValueError : <EOL> pass <EOL> for addr in addrs : <EOL> addr = str ( addr ) <EOL> log . trace ( '<STR_LIT>' . format ( addr ) ) <EOL> for port in ports : <EOL> log . trace ( '<STR_LIT>' . format ( port ) ) <EOL> try : <EOL> sock = salt . utils . network . get_socket ( addr , socket . SOCK_STREAM ) <EOL> sock . settimeout ( float ( __opts__ [ '<STR_LIT>' ] ) ) <EOL> sock . connect ( ( addr , port ) ) <EOL> sock . shutdown ( socket . SHUT_RDWR ) <EOL> sock . close ( ) <EOL> ret [ addr ] = { '<STR_LIT:host>' : addr , '<STR_LIT:port>' : port } <EOL> except socket . error : <EOL> pass <EOL> return ret </s>
