code: def save_session(fname=None, session=None, pickleProto=-1):
      
      from scapy import utils
      if fname is None:
          fname = conf.session
          if not fname:
              conf.session = fname = utils.get_temp_file(keep=True)
      log_interactive.info("Use [%s] as session file" % fname)
  
      if session is None:
          try:
              session = get_ipython().user_ns
          except Exception:
              session = six.moves.builtins.__dict__["scapy_session"]
  
      to_be_saved = session.copy()
      if "__builtins__" in to_be_saved:
          del(to_be_saved["__builtins__"])
  
      for k in list(to_be_saved):
          i = to_be_saved[k]
          if hasattr(i, "__module__") and (k[0] == "_" or i.__module__.startswith("IPython")):  # noqa: E501
              del(to_be_saved[k])
          if isinstance(i, ConfClass):
              del(to_be_saved[k])
          elif isinstance(i, (type, type, types.ModuleType)):
              if k[0] != "_":
                  log_interactive.error("[%s] (%s) can't be saved.", k, type(to_be_saved[k]))  # noqa: E501
              del(to_be_saved[k])
  
      try:
          os.rename(fname, fname + ".bak")
      except OSError:
          pass
  
      f = gzip.open(fname, "wb")
      six.moves.cPickle.dump(to_be_saved, f, pickleProto)
      f.close()
      del f
docs: Save current Scapy session to the file specified in the fname arg.
  
      params:
       - fname: file to save the scapy session in
       - session: scapy session to use. If None, the console one will be used
       - pickleProto: pickle proto version (default: -1 = latest)