def Run(self, unused_args):
    netstat = []

    for proc in psutil.process_iter():
      try:
        netstat.append((proc.pid, proc.connections()))
      except (psutil.NoSuchProcess, psutil.AccessDenied):
        pass

    for pid, connections in netstat:
      for conn in connections:
        res = rdf_client.NetworkConnection()
        res.pid = pid
        res.family = conn.family
        res.type = conn.type

        try:
          if conn.status:
            res.state = conn.status
        except __HOLE__:
          logging.warn("Encountered unknown connection status (%s).",
                       conn.status)

        res.local_address.ip, res.local_address.port = conn.laddr
        if conn.raddr:
          res.remote_address.ip, res.remote_address.port = conn.raddr

        self.SendReply(res)
dataset/ETHPy150Open google/grr/grr/client/client_actions/network.py/Netstat.Run