1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/usr/bin/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 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 General Public License for more details:
#
# Copyright (C) 2009 - 2010Red Hat, Inc.
#
import sys, dbus
DBUS_INTERFACE_PROPERTIES='org.freedesktop.DBus.Properties'
MM_DBUS_SERVICE='org.freedesktop.ModemManager'
MM_DBUS_INTERFACE_MODEM='org.freedesktop.ModemManager.Modem'
MM_DBUS_INTERFACE_MODEM_GSM_NETWORK='org.freedesktop.ModemManager.Modem.Gsm.Network'
mm_act = { 0: "unknown",
1: "GSM",
2: "GSM Compact",
3: "GPRS",
4: "EDGE",
5: "UMTS",
6: "HSDPA",
7: "HSUPA",
8: "HSPA"
}
bus = dbus.SystemBus()
proxy = bus.get_object(MM_DBUS_SERVICE, sys.argv[1])
# Properties
props = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')
mtype = props.Get(MM_DBUS_INTERFACE_MODEM, 'Type')
if mtype == 2:
print "CDMA modems do not support network scans"
sys.exit(1)
print "Driver: '%s'" % (props.Get(MM_DBUS_INTERFACE_MODEM, 'Driver'))
print "Modem device: '%s'" % (props.Get(MM_DBUS_INTERFACE_MODEM, 'MasterDevice'))
print "Data device: '%s'" % (props.Get(MM_DBUS_INTERFACE_MODEM, 'Device'))
print ""
net = dbus.Interface(proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM_GSM_NETWORK)
print "Scanning..."
try:
results = net.Scan(timeout=120)
except dbus.exceptions.DBusException, e:
print "Error scanning: %s" % e
results = {}
for r in results:
status = r['status']
if status == "1":
status = "available"
elif status == "2":
status = "current"
elif status == "3":
status = "forbidden"
else:
status = "(Unknown)"
access_tech = ""
try:
access_tech_num = int(r['access-tech'])
if access_tech_num == "0":
access_tech = "(GSM)"
elif access_tech_num == "1":
access_tech = "(Compact GSM)"
elif access_tech_num == "2":
access_tech = "(UMTS)"
elif access_tech_num == "3":
access_tech = "(EDGE)"
elif access_tech_num == "4":
access_tech = "(HSDPA)"
elif access_tech_num == "5":
access_tech = "(HSUPA)"
elif access_tech_num == "6":
access_tech = "(HSPA)"
except KeyError:
pass
opnum = "(%s):" % r['operator-num']
# Extra space for 5-digit MCC/MNC
if r['operator-num'] == 5:
opnum += " "
if r.has_key('operator-long') and len(r['operator-long']):
print "%s %s %s %s" % (r['operator-long'], opnum, status, access_tech)
elif r.has_key('operator-short') and len(r['operator-short']):
print "%s %s %s %s" % (r['operator-short'], opnum, status, access_tech)
else:
print "%s: %s %s" % (r['operator-num'], status, access_tech)
|