diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2019-12-13 15:38:33 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2019-12-16 11:30:28 +0100 |
commit | bd1fb1e1a1a1fd1660184983264d833394c456c3 (patch) | |
tree | e8629ae3ab1400ffedf3ec21db255540773bb090 | |
parent | db6279d453a1a942377c1db297174318b75cf355 (diff) |
examples: new network-scan-python example
This is currently not working completely ok because python doesn't
know how to free the GList of MMModem3gppNetwork elements.
/org/freedesktop/ModemManager1/Modem/1: starting network scan...
21403: Orange - Orange (unknown, forbidden)
21401: vodafone ES - vodafone ES (unknown, forbidden)
21403: Orange - Orange (unknown, forbidden)
21403: Orange - Orange (unknown, forbidden)
21401: vodafone ES - vodafone ES (unknown, forbidden)
21404: Yoigo - Yoigo (unknown, forbidden)
21401: vodafone ES - vodafone ES (unknown, forbidden)
21404: Yoigo - Yoigo (unknown, forbidden)
21407: Movistar - Movistar (unknown, available)
21407: Movistar - Movistar (unknown, available)
21407: Movistar - Movistar (unknown, current)
free(): invalid pointer
Aborted
(cherry picked from commit 248cd55f0e5d2a125569f9e7974a43d6b895d6de)
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | examples/Makefile.am | 2 | ||||
-rw-r--r-- | examples/network-scan-python/Makefile.am | 4 | ||||
-rw-r--r-- | examples/network-scan-python/README | 17 | ||||
-rwxr-xr-x | examples/network-scan-python/network-scan-python | 56 |
5 files changed, 79 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 8be06be6..25c350ab 100644 --- a/configure.ac +++ b/configure.ac @@ -439,6 +439,7 @@ examples/Makefile examples/modem-watcher-python/Makefile examples/modem-watcher-javascript/Makefile examples/sms-python/Makefile +examples/network-scan-python/Makefile ]) AC_OUTPUT diff --git a/examples/Makefile.am b/examples/Makefile.am index ba2da368..8d1ba663 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1 +1 @@ -SUBDIRS = modem-watcher-python modem-watcher-javascript sms-python +SUBDIRS = modem-watcher-python modem-watcher-javascript sms-python network-scan-python diff --git a/examples/network-scan-python/Makefile.am b/examples/network-scan-python/Makefile.am new file mode 100644 index 00000000..70bdfb2b --- /dev/null +++ b/examples/network-scan-python/Makefile.am @@ -0,0 +1,4 @@ + +EXTRA_DIST = \ + network-scan-python \ + $(NULL) diff --git a/examples/network-scan-python/README b/examples/network-scan-python/README new file mode 100644 index 00000000..08e5e212 --- /dev/null +++ b/examples/network-scan-python/README @@ -0,0 +1,17 @@ + +The network-scan-python program makes use of the 'libmm-glib' library through +GObject Introspection to talk to ModemManager. + +The program will: + * Detect whether ModemManager is found in the bus + * Loop through each modem found in the system, running a network scan for each + +The output will look like this: + +$ ./network-scan-python + + +Note that the program requires ModemManager and libmm-glib to be installed in +the system and the introspection typelibs available in the standard paths. + +Have fun!
\ No newline at end of file diff --git a/examples/network-scan-python/network-scan-python b/examples/network-scan-python/network-scan-python new file mode 100755 index 00000000..88f0a115 --- /dev/null +++ b/examples/network-scan-python/network-scan-python @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2019 Aleksander Morgado <aleksander@aleksander.es> +# + +import sys, signal, gi + +gi.require_version('ModemManager', '1.0') +from gi.repository import GLib, GObject, Gio, ModemManager + +if __name__ == "__main__": + + # Process input arguments + if len(sys.argv) != 1: + sys.stderr.write('error: wrong number of arguments\n') + sys.stdout.write('usage: network-scan-python\n') + sys.exit(1) + + # Connection to ModemManager + connection = Gio.bus_get_sync (Gio.BusType.SYSTEM, None) + manager = ModemManager.Manager.new_sync (connection, Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, None) + if manager.get_name_owner() is None: + sys.stderr.write('ModemManager not found in bus') + sys.exit(2) + + # Iterate modems and scan network with each one by one + for obj in manager.get_objects(): + modem3gpp = obj.get_modem_3gpp() + modem3gpp.set_default_timeout(300000) + print('%s: starting network scan...' % modem3gpp.get_object_path()) + networks = modem3gpp.scan_sync() + if networks: + for network in networks: + print('%s: %s - %s (%s, %s)' % ( + ModemManager.Modem3gpp.network_get_operator_code(network), + ModemManager.Modem3gpp.network_get_operator_short(network), + ModemManager.Modem3gpp.network_get_operator_short(network), + ModemManager.modem_access_technology_build_string_from_mask (ModemManager.Modem3gpp.network_get_access_technology(network)), + ModemManager.Modem3gppNetworkAvailability.get_string(ModemManager.Modem3gpp.network_get_availability(network)))) + else: + print('no networks found') |