:right-sidebar: True NetworkMonitor =================================================================== .. currentmodule:: gi.repository.Gio .. versionadded:: 2.32 .. class:: NetworkMonitor(*args, **kwargs) :no-contents-entry: ``GNetworkMonitor`` provides an easy-to-use cross-platform API for monitoring network connectivity. On Linux, the available implementations are based on the kernel's netlink interface and on NetworkManager. There is also an implementation for use inside Flatpak sandboxes. Methods ------- .. rst-class:: interim-class .. class:: NetworkMonitor :no-index: .. method:: can_reach(connectable: ~gi.repository.Gio.SocketConnectable, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Attempts to determine whether or not the host pointed to by ``connectable`` can be reached, without actually trying to connect to it. This may return :const:`True` even when :obj:`~gi.repository.Gio.NetworkMonitor`\:network-available is :const:`False`, if, for example, ``monitor`` can determine that ``connectable`` refers to a host on a local network. If ``monitor`` believes that an attempt to connect to ``connectable`` will succeed, it will return :const:`True`. Otherwise, it will return :const:`False` and set ``error`` to an appropriate error (such as :const:`~gi.repository.Gio.IOErrorEnum.HOST_UNREACHABLE`). Note that although this does not attempt to connect to ``connectable``\, it may still block for a brief period of time (eg, trying to do multicast DNS on the local network), so if you do not want to block, you should use :func:`~gi.repository.Gio.NetworkMonitor.can_reach_async`. .. versionadded:: 2.32 :param connectable: a :obj:`~gi.repository.Gio.SocketConnectable` :param cancellable: a :obj:`~gi.repository.Gio.Cancellable`\, or :const:`None` .. method:: can_reach_async(connectable: ~gi.repository.Gio.SocketConnectable, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously attempts to determine whether or not the host pointed to by ``connectable`` can be reached, without actually trying to connect to it. For more details, see :func:`~gi.repository.Gio.NetworkMonitor.can_reach`. When the operation is finished, ``callback`` will be called. You can then call :func:`~gi.repository.Gio.NetworkMonitor.can_reach_finish` to get the result of the operation. :param connectable: a :obj:`~gi.repository.Gio.SocketConnectable` :param cancellable: a :obj:`~gi.repository.Gio.Cancellable`\, or :const:`None` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: can_reach_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes an async network connectivity test. See :func:`~gi.repository.Gio.NetworkMonitor.can_reach_async`. :param result: a :obj:`~gi.repository.Gio.AsyncResult` .. method:: get_connectivity() -> ~gi.repository.Gio.NetworkConnectivity Gets a more detailed networking state than :func:`~gi.repository.Gio.NetworkMonitor.get_network_available`. If :obj:`~gi.repository.Gio.NetworkMonitor`\:network-available is :const:`False`, then the connectivity state will be :const:`~gi.repository.Gio.NetworkConnectivity.LOCAL`. If :obj:`~gi.repository.Gio.NetworkMonitor`\:network-available is :const:`True`, then the connectivity state will be :const:`~gi.repository.Gio.NetworkConnectivity.FULL` (if there is full Internet connectivity), :const:`~gi.repository.Gio.NetworkConnectivity.LIMITED` (if the host has a default route, but appears to be unable to actually reach the full Internet), or :const:`~gi.repository.Gio.NetworkConnectivity.PORTAL` (if the host is trapped behind a "captive portal" that requires some sort of login or acknowledgement before allowing full Internet access). Note that in the case of :const:`~gi.repository.Gio.NetworkConnectivity.LIMITED` and :const:`~gi.repository.Gio.NetworkConnectivity.PORTAL`, it is possible that some sites are reachable but others are not. In this case, applications can attempt to connect to remote servers, but should gracefully fall back to their "offline" behavior if the connection attempt fails. .. versionadded:: 2.44 .. classmethod:: get_default() -> ~gi.repository.Gio.NetworkMonitor Gets the default :obj:`~gi.repository.Gio.NetworkMonitor` for the system. .. versionadded:: 2.32 .. method:: get_network_available() -> bool Checks if the network is available. "Available" here means that the system has a default route available for at least one of IPv4 or IPv6. It does not necessarily imply that the public Internet is reachable. See :obj:`~gi.repository.Gio.NetworkMonitor`\:network-available for more details. .. versionadded:: 2.32 .. method:: get_network_metered() -> bool Checks if the network is metered. See :obj:`~gi.repository.Gio.NetworkMonitor`\:network-metered for more details. .. versionadded:: 2.46 Properties ---------- .. rst-class:: interim-class .. class:: NetworkMonitor :no-index: .. attribute:: props.connectivity :type: ~gi.repository.Gio.NetworkConnectivity The type of the None singleton. .. versionadded:: 2.44 .. attribute:: props.network_available :type: bool The type of the None singleton. .. versionadded:: 2.32 .. attribute:: props.network_metered :type: bool The type of the None singleton. .. versionadded:: 2.46 Signals ------- .. rst-class:: interim-class .. class:: NetworkMonitor.signals :no-index: .. method:: network_changed(network_available: bool) -> None The type of the None singleton. .. versionadded:: 2.32 :param network_available: the current value of :obj:`~gi.repository.Gio.NetworkMonitor`\:network-available Virtual Methods --------------- .. rst-class:: interim-class .. class:: NetworkMonitor :no-index: .. method:: do_can_reach(connectable: ~gi.repository.Gio.SocketConnectable, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Attempts to determine whether or not the host pointed to by ``connectable`` can be reached, without actually trying to connect to it. This may return :const:`True` even when :obj:`~gi.repository.Gio.NetworkMonitor`\:network-available is :const:`False`, if, for example, ``monitor`` can determine that ``connectable`` refers to a host on a local network. If ``monitor`` believes that an attempt to connect to ``connectable`` will succeed, it will return :const:`True`. Otherwise, it will return :const:`False` and set ``error`` to an appropriate error (such as :const:`~gi.repository.Gio.IOErrorEnum.HOST_UNREACHABLE`). Note that although this does not attempt to connect to ``connectable``\, it may still block for a brief period of time (eg, trying to do multicast DNS on the local network), so if you do not want to block, you should use :func:`~gi.repository.Gio.NetworkMonitor.can_reach_async`. .. versionadded:: 2.32 :param connectable: a :obj:`~gi.repository.Gio.SocketConnectable` :param cancellable: a :obj:`~gi.repository.Gio.Cancellable`\, or :const:`None` .. method:: do_can_reach_async(connectable: ~gi.repository.Gio.SocketConnectable, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously attempts to determine whether or not the host pointed to by ``connectable`` can be reached, without actually trying to connect to it. For more details, see :func:`~gi.repository.Gio.NetworkMonitor.can_reach`. When the operation is finished, ``callback`` will be called. You can then call :func:`~gi.repository.Gio.NetworkMonitor.can_reach_finish` to get the result of the operation. :param connectable: a :obj:`~gi.repository.Gio.SocketConnectable` :param cancellable: a :obj:`~gi.repository.Gio.Cancellable`\, or :const:`None` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: do_can_reach_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes an async network connectivity test. See :func:`~gi.repository.Gio.NetworkMonitor.can_reach_async`. :param result: a :obj:`~gi.repository.Gio.AsyncResult` .. method:: do_network_changed(network_available: bool) -> None The type of the None singleton. :param network_available: