Re: Automatic re-connect script for 3G connections (van Schelve)



Am Freitag, den 22.10.2010, 11:17 +0200 schrieb Florian Hackenberger
<f hackenberger chello at>:
> Hi!
> 
> dcbw on #nm told me that van Schelve has a script at hand which 
> automatically reconnects nm manager using a 3G connection.
> 
> van Schelve: Would you mind sharing that script with me?
> 
> Thanks in advance, Florian

Hi!

That's not completely correct. I wrote a script to dialup a 3G
connection conditionally. The intention for this script was to bring up
a 3g connection during gnome-autostart when a user logs in and after
suspend / resume.

I won't use the autoconnect feature from network-manager at that time.

Dan: I am interesting in automatically reconnect a broken mobile 3G
connection as well ;-)

Attached you can find my script. Hope it will help you!

#!/usr/bin/python

import dbus,syslog,time

syslog.openlog('wwan-autoconnect')

bus = dbus.SystemBus()

def print_one_services_connections(service_name, desc):
	# Ask the settings service for the list of connections it provides
	proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManagerSettings")
	settings = dbus.Interface(proxy, "org.freedesktop.NetworkManagerSettings")
	connection_paths = settings.ListConnections()

# List each connection's name, UUID, and type
	for path in connection_paths:
		con_proxy = bus.get_object(service_name, path)
		connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManagerSettings.Connection")
		config = connection.GetSettings()

		# Get the details of the 'connection' setting
		s_con = config['connection']
		if s_con['id'] == "MYCONN":
			return path

def print_devices(service_name, desc):
	# Ask the settings service for the list of connections it provides
	proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManager")
	nm = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
	device_paths = nm.GetDevices()

	# List each device
	for path in device_paths:
		con_proxy = bus.get_object(service_name, path)
		connection = dbus.Interface(con_proxy, "org.freedesktop.DBus.Properties")
		prop = connection.Get('org.freedesktop.NetworkManager.Device','DeviceType')
		# We are only interested in GSM devices
		if prop == 3:
			return path


bus = dbus.SystemBus()

# constants for accessing gnome network manager
busName = 'org.freedesktop.NetworkManager'
busPath = '/org/freedesktop/NetworkManager'
busInterface = 'org.freedesktop.NetworkManager'

proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
status = dbus.Interface(proxy, "org.freedesktop.DBus.Properties").Get("org.freedesktop.NetworkManager","State")

if status == 4:
	syslog.syslog("Starte Mobilverbindung")
	#time.sleep(15)
	nm = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
	con = print_one_services_connections("org.freedesktop.NetworkManager", "System")
	if con != None:
		for i in range(5):
			dev = print_devices("org.freedesktop.NetworkManager", "System")
			if dev == None:
				time.sleep(2)
			else:
				break
		if dev != None:
			nm.ActivateConnection("org.freedesktop.NetworkManagerSystemSettings",con,dev,"/")
		else:
			syslog.syslog("Kein aktives Modem gefunden")
	else:
		syslog.syslog("Keine Mobilkonfiguration vorhanden")
else:
	syslog.syslog("Netzwerk ist aktiv. Mobile Einwahl nicht erforderlich")


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]