Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # encoding:utf8
- """
- IMEI 号码分析工具
- update by hysia
- http://blog.hysia.com
- http://weibo.com/hysia
- 2011/11/20
- """
- import re
- import urllib
- import urllib2
- import cookielib
- import sys
- import socket
- from optparse import OptionParser
- IMEI_INFO = {
- 'Type Allocation Holder' : r'''Type Allocation Holder</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
- 'Mobile Equipment Type' : r'''Mobile Equipment Type</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
- 'GSM Implementation Phase' : r'''GSM Implementation Phase</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
- 'Primary Market' : r'''Primary Market</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
- 'Legal Basis for Allocation' : r'''Legal Basis for Allocation</td>[\s\S]*?<td class="basic-text">(.*?)</td>''',
- 'Full IMEI Presentation' : r'''Full IMEI Presentation</td>[\s\S]*?<td class="basic-text">(.*?)</td>'''
- }
- def login():
- loginUrl = 'https://www.numberingplans.com/?page=account&sub=login'
- postData = urllib.urlencode({'username':'你的用户名','password':'你的密码'})
- cj = cookielib.CookieJar()
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
- opener.addheaders = [('User-Agent','Mozilla/4.0 (compatible; MSIE 6.1; Windows NT)')]
- urllib2.install_opener(opener)
- req = urllib2.Request(loginUrl,postData)
- conn = urllib2.urlopen(req)
- def getUrlData(url,postData):
- retVal = None
- req = urllib2.Request(url,postData)
- f = urllib2.urlopen(req)
- try:
- retVal = f.read()
- except:
- print "Get Url Data Error!"
- finally:
- f.close
- return retVal
- def analysisIMEI(num):
- retVal = {}
- url = "http://www.numberingplans.com/?page=analysis&sub=imeinr"
- postData = "i=%s" %num
- htmlData = getUrlData(url,postData)
- #print htmlData
- for info in IMEI_INFO:
- m = re.search(IMEI_INFO[info],htmlData)
- if m:
- retVal[info] = m.groups()[0].strip()
- #print retVal
- return retVal
- if __name__ == '__main__':
- socket.setdefaulttimeout(20)
- parser = OptionParser()
- parser.add_option("-i","--imei", dest = "imei", help = u"手机的IMEI字符串,你可以通过手机拨号 *#06# 查看IMEI号码\n例如:357194040705758")
- parser.add_option("-l", "--login", dest = "login", action="store_true", default=False, help = u"登录检测IMEI信息,默认不开启")
- (options, args) = parser.parse_args()
- if not options.imei:
- parser.print_help()
- sys.exit(1)
- try:
- imei = options.imei
- msg = u"检索IMEI信息..."
- print msg
- if options.login:
- print u"你开启了登录后检索,如果检索失败,那就是账号检索受限."
- login()
- imeiInfo = analysisIMEI(imei)
- if imeiInfo:
- info = u"IMEI信息: %s \n" %imeiInfo['Full IMEI Presentation']
- info += u"手机制造商: %s \n" %imeiInfo['Type Allocation Holder']
- info += u"手机型号: %s \n" %imeiInfo['Mobile Equipment Type']
- info += u"销售市场: %s \n" %imeiInfo['Primary Market']
- print info
- else:
- print u"检索失败.可能是网络问题或不正确的IMEI号码,请重试"
- except:
- print 'Usage: python imei.py 357194040705758'
- sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement