code: def net_if_stats():
      """Get NIC stats (isup, duplex, speed, mtu)."""
      names = net_io_counters().keys()
      ret = {}
      for name in names:
          try:
              mtu = cext_posix.net_if_mtu(name)
              isup = cext_posix.net_if_is_running(name)
              duplex, speed = cext_posix.net_if_duplex_speed(name)
          except OSError as err:
              # https://github.com/giampaolo/psutil/issues/1279
              if err.errno != errno.ENODEV:
                  raise
          else:
              if hasattr(_common, "NicDuplex"):
                  duplex = _common.NicDuplex(duplex)
              ret[name] = _common.snicstats(isup, duplex, speed, mtu)
      return ret
  
imports: import contextlib
  import errno
  import functools
  import os
  from collections import namedtuple
  from .None import _common
  from .None import _psposix
  from .None import _psutil_osx
  from .None import _psutil_posix
  from ._common import AccessDenied
  from ._common import conn_tmap
  from ._common import conn_to_ntuple
  from ._common import isfile_strict
  from ._common import memoize_when_activated
  from ._common import NoSuchProcess
  from ._common import parse_environ_block
  from ._common import usage_percent
  from ._common import ZombieProcess
  from ._compat import PermissionError
  from ._compat import ProcessLookupError
label_desc: Use image node_id 12 for calling a global function with example usage: net_if_stats() and returns: ret