SHARE
TWEET

IMEI-INFO

a guest Nov 20th, 2011 571 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # encoding:utf8
  3.  
  4. """
  5. IMEI 号码分析工具
  6. update by hysia
  7. http://blog.hysia.com
  8. http://weibo.com/hysia
  9. 2011/11/20
  10. """
  11. import re
  12. import urllib
  13. import urllib2
  14. import cookielib
  15. import sys
  16. import socket
  17. from optparse import OptionParser
  18.  
  19. IMEI_INFO = {
  20.     'Type Allocation Holder' : r'''Type Allocation Holder</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
  21.     'Mobile Equipment Type' : r'''Mobile Equipment Type</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
  22.     'GSM Implementation Phase' : r'''GSM Implementation Phase</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
  23.     'Primary Market' : r'''Primary Market</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
  24.     'Legal Basis for Allocation' : r'''Legal Basis for Allocation</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
  25.     'Full IMEI Presentation' : r'''Full IMEI Presentation</td>[\s\S]*?<td class="basic-text">(.*?)</td>'''
  26. }
  27.  
  28. def login():
  29.         loginUrl = 'https://www.numberingplans.com/?page=account&sub=login'
  30.         postData = urllib.urlencode({'username':'你的用户名','password':'你的密码'})
  31.         cj = cookielib.CookieJar()
  32.         opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  33.         opener.addheaders = [('User-Agent','Mozilla/4.0 (compatible; MSIE 6.1; Windows NT)')]
  34.         urllib2.install_opener(opener)
  35.         req = urllib2.Request(loginUrl,postData)
  36.         conn = urllib2.urlopen(req)
  37.        
  38. def getUrlData(url,postData):
  39.         retVal = None
  40.         req = urllib2.Request(url,postData)
  41.         f = urllib2.urlopen(req)
  42.         try:
  43.                 retVal = f.read()              
  44.         except:
  45.                 print "Get Url Data Error!"
  46.         finally:
  47.                 f.close
  48.                
  49.         return retVal
  50.  
  51. def analysisIMEI(num):
  52.         retVal = {}
  53.         url = "http://www.numberingplans.com/?page=analysis&sub=imeinr"
  54.         postData = "i=%s" %num
  55.         htmlData = getUrlData(url,postData)
  56.         #print htmlData
  57.         for info in IMEI_INFO:
  58.                 m = re.search(IMEI_INFO[info],htmlData)
  59.                 if m:
  60.                         retVal[info] = m.groups()[0].strip()
  61.                         #print retVal
  62.         return retVal
  63.        
  64.                
  65. if __name__ == '__main__':
  66.  
  67.         socket.setdefaulttimeout(20)
  68.        
  69.         parser = OptionParser()
  70.         parser.add_option("-i","--imei", dest = "imei", help = u"手机的IMEI字符串,你可以通过手机拨号 *#06#  查看IMEI号码\n例如:357194040705758")
  71.         parser.add_option("-l", "--login", dest = "login", action="store_true", default=False, help = u"登录检测IMEI信息,默认不开启")
  72.         (options, args) = parser.parse_args()
  73.         if not options.imei:
  74.                 parser.print_help()
  75.                 sys.exit(1)
  76.                
  77.         try:
  78.                 imei = options.imei
  79.                 msg = u"检索IMEI信息..."
  80.                 print msg
  81.                 if options.login:
  82.                         print u"你开启了登录后检索,如果检索失败,那就是账号检索受限."
  83.                         login()
  84.                        
  85.                 imeiInfo = analysisIMEI(imei)
  86.  
  87.                 if imeiInfo:
  88.                         info = u"IMEI信息: %s \n" %imeiInfo['Full IMEI Presentation']
  89.                         info += u"手机制造商: %s \n" %imeiInfo['Type Allocation Holder']
  90.                         info += u"手机型号: %s \n" %imeiInfo['Mobile Equipment Type']
  91.                         info += u"销售市场: %s \n" %imeiInfo['Primary Market']
  92.                         print info
  93.                 else:
  94.                         print u"检索失败.可能是网络问题或不正确的IMEI号码,请重试"
  95.         except:
  96.                 print 'Usage: python imei.py 357194040705758'
  97.                 sys.exit(0)
  98.  
  99.  
RAW Paste Data
Want to get better at Python?
Learn to code Python in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top