Tuesday, October 21, 2014

auto redial 3G connection on Linux

1- Install  sakis3g by following this link
http://theamdara.blogspot.com/2014/10/connect-internet-using-3g-modem-on-linux.html

2- Configure the 3G setting, APN, username and password by edit /etc/sakis3g.conf as bellow
SGUI="interactive terminal"
USBINTERFACE="0"
APN="3g-provider-APN"
APN_USER="username"
APN_PASS="password"



3- Save the following script 3g-conn.py
#!/usr/bin/python
import time
import re
import os

close = 0
while close < 1:
    oneMin = 0
    getInterface = os.popen("ifconfig").read()
    if re.search("ppp0", getInterface):
        if (oneMin % 30) == 0:
            print "Stay connected"
            oneMin += 10
    else:
        print "lose conn tring to connect again"
        os.system("sakis3gz connect")
        os.system("echo nameserver 8.8.4.4 > /etc/resolv.conf")   
    time.sleep(12)


4- run the script and it will check the connection every 12 second then if the connection is lost, it will redial the connection again
root@mypc# python 3g-conn.py



No comments:

Post a Comment