def _remotes_on(port, which_end):
 port = int(port)
 ret = set()
 proc_available = False
 for statf in ['/proc/net/tcp', '/proc/net/tcp6']:
  if os.path.isfile(statf):
   proc_available = True
   with salt.utils.fopen(statf, 'r') as fp_:
    for line in fp_:
     if line.strip().startswith('sl'):
      continue
     iret = _parse_tcp_line(line)
     sl = next(iter(iret))
     if (iret[sl][which_end] == port):
      ret.add(iret[sl]['remote_addr'])
 if (not proc_available):
  if salt.utils.is_sunos():
   return _sunos_remotes_on(port, which_end)
  if salt.utils.is_freebsd():
   return _freebsd_remotes_on(port, which_end)
  if salt.utils.is_netbsd():
   return _netbsd_remotes_on(port, which_end)
  if salt.utils.is_openbsd():
   return _openbsd_remotes_on(port, which_end)
  if salt.utils.is_windows():
   return _windows_remotes_on(port, which_end)
  return _linux_remotes_on(port, which_end)
 return ret

def _remotes_on ( port , which_end ) : port = int ( port ) ret = set ( ) proc_available = False for statf in [ '/proc/net/tcp' , '/proc/net/tcp6' ] : if os . path . isfile ( statf ) : proc_available = True with salt . utils . fopen ( statf , 'r' ) as fp_ : for line in fp_ : if line . strip ( ) . startswith ( 'sl' ) : continue iret = _parse_tcp_line ( line ) sl = next ( iter ( iret ) ) if ( iret [ sl ] [ which_end ] == port ) : ret . add ( iret [ sl ] [ 'remote_addr' ] ) if ( not proc_available ) : if salt . utils . is_sunos ( ) : return _sunos_remotes_on ( port , which_end ) if salt . utils . is_freebsd ( ) : return _freebsd_remotes_on ( port , which_end ) if salt . utils . is_netbsd ( ) : return _netbsd_remotes_on ( port , which_end ) if salt . utils . is_openbsd ( ) : return _openbsd_remotes_on ( port , which_end ) if salt . utils . is_windows ( ) : return _windows_remotes_on ( port , which_end ) return _linux_remotes_on ( port , which_end ) return ret
return a set of ip addrs active tcp connections .