2014-06-20 10:48:23 -05:00
|
|
|
#!/usr/bin/env python
|
2019-09-10 11:19:01 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2014-06-20 10:48:23 -05:00
|
|
|
#
|
|
|
|
|
# Copyright (C) 2011 - 2012 Red Hat, Inc.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
import dbus, sys
|
|
|
|
|
|
|
|
|
|
# This example indicates whether the default network connection is known to be WWAN
|
|
|
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
|
|
|
|
|
|
# Exit early if NetworkManager is not running
|
|
|
|
|
proxy = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
|
|
|
|
|
busdaemon = dbus.Interface(proxy, "org.freedesktop.DBus")
|
2020-06-30 16:21:00 -04:00
|
|
|
if not busdaemon.NameHasOwner("org.freedesktop.NetworkManager"):
|
2017-12-02 12:44:50 +08:00
|
|
|
print("NetworkManager not running")
|
2014-06-20 10:48:23 -05:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
# Get a proxy for the NetworkManager object
|
2020-06-30 16:21:00 -04:00
|
|
|
proxy = bus.get_object(
|
|
|
|
|
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager"
|
|
|
|
|
)
|
|
|
|
|
props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
|
2014-06-20 10:48:23 -05:00
|
|
|
|
2020-06-30 16:21:00 -04:00
|
|
|
# Shortcut #1, for NM 1.0
|
|
|
|
|
try:
|
|
|
|
|
ctype = props.Get("org.freedesktop.NetworkManager", "PrimaryConnectionType")
|
2020-06-09 16:28:32 -04:00
|
|
|
if ctype == "":
|
2017-12-02 12:44:50 +08:00
|
|
|
print("No active connection")
|
2014-11-13 14:27:26 -05:00
|
|
|
elif ctype in ["gsm", "cdma", "bluetooth"]:
|
2017-12-02 12:44:50 +08:00
|
|
|
print("WWAN is default")
|
2014-11-13 14:27:26 -05:00
|
|
|
else:
|
2017-12-02 12:44:50 +08:00
|
|
|
print("WWAN is not default")
|
2014-11-13 14:27:26 -05:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|