Saturday 17 August 2013

Linux Tweaks to Unlock Huawei Modem using Python

#borrowed from (Zenu)

  If you wonna unlock your 3G Modem and you have linux installed in your system you just need to follow the two stipulated steps below... They all are simple
  1. Unlock the modem using Simbwa Phillip steps.
  2. Set the APN of the SIM Network whenever initializing the modem 
A) Using the Simbwa Phillip Steps
Two ways of unlocking your 3G modem (first– the easyway, second, the geeky way).
Prerequisites:
a). Python 2.6 or greater
b). For the easyway (huawei modems), download and install pyhumod 0.03 from here . If you choose to go the geeky way, you don’t need the pyhumod. Also if the easy way fails, go the geeky way
The easy way Huawei modem:
Paste the following code in your preferred linux editor even if its the console  and save it as whatever name you choose (e.g huawei_unlocker.py)
#!/usr/bin/env python

import hashlib
import humod
UNLOCK_SALT = "5e8dd316726b0335"

def show_code(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

mod = humod.Modem()
imei = mod.show_imei()
status = humod.at_commands.Command(mod,'AT^CARDLOCK="'+str(show_code(imei,UNLOCK_SALT))+'"\r')
#------------------- code ends here -----------------------------

After save the file and quit your editor
Check that you have plugged in your modem and has been detected by system. (“dmesg | tail” could help. Check that you have ttyUSB0, ttyUSBx where x could be 1 or 2)
Execute the python script on commandline like so:
python huawei_unlocker.py
Thats it!
2). The geeky way
Plug in your modem
Check that its has been read by the system
Then at your terminal type:
# cat /dev/ttyUSB0 &
We then extract the IMEI serial of the modem like so:
# echo -e “ATI\r” > /dev/ttyUSB0
Make note of the IMEI serial
In your favorite editor paste the following code and save it as unlock.py
 #!/usr/bin/env python

import hashlib
UNLOCK_SALT = "5e8dd316726b0335"

def show_codes(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

# PLEASE TYPE YOUR IMEI  BELOW
imei = ' '
if(imei == ' '):
    print 'Please open this script from your editor and enter your IMEI'
else:
    print "Your Modem unlock code: %s" % show_codes(imei,UNLOCK_SALT);
Execute the above script to generate your modem unlock code
Now its time to unlock the modem and we do it like so:

# echo -e 'AT^CARDLOCK="XXXXXXXX"\r' > /dev/ttyUSB0

(Please use your generated modem unlock code in place of XXXXXXXX)
You should see the modem reply with an OK
Press CTRL + C



B)Set the APN of the SIM Network whenever initializing the modem

i - For linux if your using wvdial change the wvdial.conf or add the line below which sets the APN name
Init3 = AT+CGDCONT=1,"IP","TelecomNetworkAPNName"
ii - For windows users, go to the device manager -> Modems -> Open properties of the modem -> Under Advanced -> in the extra initialization commands field put the entry
AT+CGDCONT=1,"IP","TelecomNetworkAPNName"
The TelecomNetworkAPNName varies from Telecom, for UTL it is utweb and for Orange it is orange.ug.
So now you can create a connection with a dial number *99# or *99***1#.

 

3 comments:

  1. There are many ways to unlock a Huawei modem and I used a safe unlocking method...I got the unlock code for my Huawei modem from Wickedunlock.com and removed the network lock permanently.

    ReplyDelete
  2. njoro ....nikii humod irarehe error?

    ReplyDelete