PDA

View Full Version : [SOLVED] Limit time connected to internet via gprs



UbuKunubi
March 26th, 2009, 12:18 AM
Hello Folks,
Using Ubuntu Hardy and Python 2.4 I have configured a PC that will use pppd to happily connect to the internet.
Im trying to achieve the following (basically automate the internet connection) :

1) Connect to the internet (send the 'pppd call gprs' command to terminal).
2) perform an internet task (this I've sorted)
3) Disconnect from the internet (send Ctrl 'c' to the abort the gprs connection).

Can anyone please help?
I've gone google blind with trying to solve this for the last month.
The main problem im encountering is conflicting information between the different versions of python, and the different ways of performing commands!

Many thanks in anticipation,
Ubu.

UbuKunubi
March 27th, 2009, 12:18 AM
Bump.

I've been searching further for an answer to this and the more i look, the confused i've become.

dbus, pipes, and ncurses are just some of the topics i've seen. But if anyone can give me nudge in the right direction i'd be grateful.

It seems inordinately difficult to what I thought was an easy task.

Thanks in advance,
Ubu.

UbuKunubi
March 29th, 2009, 09:54 PM
48 hours since Bump.

Is this impossible? Is there no way to use python to send the 'pppd call gprs' command to terminal, and then send the Ctrl+c to the same terminal after 5 minutes?

wmcbrine
March 30th, 2009, 08:01 PM
Back in my dialup days, I used to use something called "diald" for this purpose. It would connect automatically on network activity, and disconnect after a few minutes of inactivity. I just did a brief search, and it looks like it hasn't been updated in ten years, and may or may not still be available. But surely there are modern substitutes. Maybe pppd would even handle it by itself.

As far as getting Python to start and stop pppd, it will be easier if you forget about the terminal. Just use the subprocess module:



import os
import signal
import subprocess
import time

pppd = subprocess.Popen(['/usr/bin/pppd', 'call', 'gprs']) # Start pppd
time.sleep(300) # Your five minutes online
os.kill(pppd.pid, signal.SIGINT) # ^C to pppd

UbuKunubi
November 15th, 2009, 02:44 PM
Back in my dialup days, I used to use something called "diald" for this purpose. It would connect automatically on network activity, and disconnect after a few minutes of inactivity. I just did a brief search, and it looks like it hasn't been updated in ten years, and may or may not still be available. But surely there are modern substitutes. Maybe pppd would even handle it by itself.

As far as getting Python to start and stop pppd, it will be easier if you forget about the terminal. Just use the subprocess module:



import os
import signal
import subprocess
import time

pppd = subprocess.Popen(['/usr/bin/pppd', 'call', 'gprs']) # Start pppd
time.sleep(300) # Your five minutes online
os.kill(pppd.pid, signal.SIGINT) # ^C to pppd


Thanks for your time with that code sample.
I recently had an ISP failure, so was looking for this so I could use my phone as a modem.

This is just the kind of code sample I wanted.
Many thanks,
Ubu.