def get_connected_hosts(): ''' 连接所有主机, 并返回连接结果list :return: a list eg: [<连接对象>, ...] ''' hosts_info = get_env_hosts_info() my_group = [] for item in hosts_info: _ = group.Connection(host=item.get('ip'), user=item.get('user'), port=item.get('port'), connect_timeout=6, connect_kwargs={'password': item.get('passwd')}) my_group.append(_) # print(my_group) return my_group
def get_connected_hosts(): ''' 连接所有主机, 并返回连接结果list :return: a list eg: [<连接对象>, ...] ''' hosts_info = get_env_hosts_info() my_group = [] for item in hosts_info: ip = item.get('ip', '') if is_out_server: if ip == '176.122.147.85': continue else: pass if ip.startswith('192'): # 内网跳过 continue else: pass else: if not ip.startswith('192'): continue else: pass # if '118.31' in ip: # continue print('目标ip: {}'.format(ip)) _ = group.Connection(host=ip, user=item.get('user'), port=item.get('port'), connect_timeout=6, connect_kwargs={'password': item.get('passwd')}) my_group.append(_) # print(my_group) return my_group