Advertisement
khanhnnvn

Get info sim card using Python

Jan 29th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import sys
  2. import time
  3. import serial
  4. def command(device, cmd):
  5.     device.flush()
  6.     device.write(cmd)
  7.     time.sleep(0.2)
  8.     wait = device.inWaiting()
  9.     read = device.read(wait)
  10.     result = read.strip().split('\r\n')
  11.     return result
  12. def get_manufacturer(device):
  13.     return command(device, 'AT+CGMI\r')
  14. def get_model(device):
  15.     return command(device, 'AT+CGMM\r')
  16. def get_imei(device):
  17.     return command(device, 'AT+CGSN\r')
  18. def get_sw_version(device):
  19.     return command(device, 'AT+CGMR\r')
  20. def get_msisdn(device):
  21.     return command(device, 'AT+CNUM\r')
  22. def get_imsi(device):
  23.     return command(device, 'AT+CIMI\r')
  24. if __name__ == '__main__':
  25.     try:
  26.         port = raw_input('Moi ban nhap cong: ')
  27.         dev = serial.Serial(port='COM'+port)
  28.     except Exception, e:
  29.         print e
  30.         sys.exit(1)
  31.     print 'MANUFACTURER: ',
  32.     print get_manufacturer(dev)
  33.     print 'MODEL: ',
  34.     print get_model(dev)
  35.     print 'IMEI: ',
  36.     print get_imei(dev)
  37.     print 'SOFTWARE: ',
  38.     print get_sw_version(dev)
  39.     print 'MSISDN: ',
  40.     print get_msisdn(dev)
  41.     print 'IMSI: ',
  42.     print get_imsi(dev)
  43.     #
  44.     dev.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement