def _freebsd_remotes_on(port, which_end):
 port = int(port)
 remotes = set()
 try:
  cmd = salt.utils.shlex_split('sockstat -4 -c -p {0}'.format(port))
  data = subprocess.check_output(cmd)
 except subprocess.CalledProcessError as ex:
  log.error('Failed "sockstat" with returncode = {0}'.format(ex.returncode))
  raise
 lines = salt.utils.to_str(data).split('\n')
 for line in lines:
  chunks = line.split()
  if (not chunks):
   continue
  if ('COMMAND' in chunks[1]):
   continue
  if (len(chunks) < 2):
   continue
  local = chunks[5]
  remote = chunks[6]
  (lhost, lport) = local.split(':')
  (rhost, rport) = remote.split(':')
  if ((which_end == 'local') and (int(lport) != port)):
   continue
  if ((which_end == 'remote') and (int(rport) != port)):
   continue
  remotes.add(rhost)
 return remotes

def _freebsd_remotes_on ( port , which_end ) : port = int ( port ) remotes = set ( ) try : cmd = salt . utils . shlex_split ( 'sockstat -4 -c -p {0}' . format ( port ) ) data = subprocess . check_output ( cmd ) except subprocess . CalledProcessError as ex : log . error ( 'Failed "sockstat" with returncode = {0}' . format ( ex . returncode ) ) raise lines = salt . utils . to_str ( data ) . split ( '\n' ) for line in lines : chunks = line . split ( ) if ( not chunks ) : continue if ( 'COMMAND' in chunks [ 1 ] ) : continue if ( len ( chunks ) < 2 ) : continue local = chunks [ 5 ] remote = chunks [ 6 ] ( lhost , lport ) = local . split ( ':' ) ( rhost , rport ) = remote . split ( ':' ) if ( ( which_end == 'local' ) and ( int ( lport ) != port ) ) : continue if ( ( which_end == 'remote' ) and ( int ( rport ) != port ) ) : continue remotes . add ( rhost ) return remotes
returns set of ipv4 host addresses of remote established connections on local tcp port port .