Created
December 3, 2015 23:09
-
-
Save gnuton/3ba6dca3ce27d13833da to your computer and use it in GitHub Desktop.
Python script which switch Huawey hilink e3372 to debug mode, then sends some command to its serial console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
# retrieve token | |
url="http://192.168.8.1/api/webserver/token" | |
response = urllib2.urlopen(url) | |
xml=response.read() | |
token=xml[59:-23] | |
print "Got token %s" % token | |
# switch device to debug mode | |
payload='<request><mode>1</mode></request>' | |
url='http://192.168.8.1/api/device/mode' | |
headers = { 'Content-type': 'text/xml', | |
' __RequestVerificationToken': token } | |
req = urllib2.Request(url, payload, headers) | |
response = urllib2.urlopen(req) | |
print response | |
# | |
import serial | |
p='/dev/ttyUSB0' | |
ser = serial.Serial(port=p, timeout=1) | |
def read(cmd, txt): | |
ser.write(cmd + "\r\n") | |
for l in ser.read(100000).split("\r\n"): | |
if txt in l: | |
return l.split(":")[1].strip() | |
print read("AT^SETPORT?", "SETPORT") | |
print read("AT^DATALOCK?", "DATALOCK") | |
print read("AT^CARDLOCK?", "CARDLOCK") | |
IMEI= read("ATI", "IMEI") | |
print IMEI | |
model= read("ATI", "Model") | |
print model | |
ser.write('AT^DATALOCK=49158354\r\n') #ERROR | |
## The function which generate unlock codes from the IMEI is the following. | |
## Note the salt is the V1. New modems have different salt | |
import hashlib | |
def getCode(imei, salt): | |
digest = hashlib.md5((imei+salt).lower()).digest() | |
code = 0 | |
for i in range(0,4): | |
code += (ord(digest[i])^ord(digest[4+i])^ord(digest[8+i])^ord(digest[12+i])) << (3-i)*8 | |
code &= 0x1ffffff | |
code |= 0x2000000 | |
return code | |
# Your IMEI goes here: | |
imei = "867012020543887" | |
print "Unlock code: %s" % getCode(imei, "5e8dd316726b0335") | |
print "Flash code: %s" % getCode(imei, "97b7bc6be525ab44") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para liberar huawei b612 533 .alguien tiene un metodo ?