Skip to content

Instantly share code, notes, and snippets.

@gnuton
Created January 13, 2016 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnuton/034e9353b51ab5af7ab8 to your computer and use it in GitHub Desktop.
Save gnuton/034e9353b51ab5af7ab8 to your computer and use it in GitHub Desktop.
Script to connect e3372s-153 stick firmware to internet on Linux
## Reference https://lists.openwrt.org/pipermail/openwrt-devel/2015-July/034094.html
import serial
from subprocess import call
from time import sleep
p='/dev/ttyUSB1'
def toIP(octet):
n=2
ipArray = [int(octet[i:i+n],16) for i in range(0, len(octet), n)][::-1]
return ".".join(map(str, ipArray))
ser = serial.Serial(port=p, timeout=4)
ser.write('ATZ\r\n')
print(ser.read(500))
ser.write('ATQ0 V1 E1 S0=0\r\n')
print(ser.read(500))
ser.write('AT^NDISDUP=1,1,"internet"\r\n')
print(ser.read(500))
sleep(5)
ser.write('AT^DHCP?\r\n')
output=ser.read(500)
got_dhcp=False
for line in output.split("\n"):
if(line[:7] != "^DHCP: "):
continue
got_dhcp=True
print "LINE"
print line
ips= map(toIP, line[7:].split(","))
print ips
c=call(["ifconfig", "wwan0", ips[0], "netmask", ips[1], "up"])
if (c!=0):
print "ERROR: Setting interface"
c=call(["route", "add", "-net", "default", "gw", ips[2]])
if (c!=0):
print "ERROR: Setting default router"
if (got_dhcp == False):
print "Running dhclient..."
c=call("dhclient","wwan0")
print "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment