Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from queue import Queue
- import asyncio
- import aiohttp
- import random
- import requests
- CATCH = True
- proxies_queue = Queue()
- def indexes():
- n = 0
- while True:
- n += 1
- yield str(n)
- counter = indexes()
- class TryAgain(Exception):
- pass
- class Turbo:
- def __init__(self, target, number):
- # self.login = login
- # self.password = password
- self.target = target
- self.number = number
- self.proxy = None
- async def start(self):
- self.proxy = proxies_queue.get() if use_proxy == 'y' else None
- async with aiohttp.ClientSession() as session:
- while CATCH:
- try:
- res = await session.get('https://www.instagram.com/{0}'.format(self.target),
- proxy=self.proxy
- )
- print('Task: {} Try:{} Target:{} Code:{}'.format(self.number, next(counter), self.target, res.status))
- if res.status == 404:
- changer.change_username()
- if res.status == 429:
- if use_proxy == 'y':
- print('task {} is banned. take new proxy'.format(self.number))
- old_proxy = self.proxy
- proxies_queue.put(self.proxy)
- self.proxy = proxies_queue.get()
- print('task {} got new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
- else:
- print('task {} is banned. sleep'.format(self.number))
- await asyncio.sleep(60 * 3)
- print('task {} waked up. try to make requests')
- except Exception as ex:
- print('task {} error {} so change proxy'.format(self.number, ex.__repr__()))
- # print(await session.get('https://www.google.com/'))
- if use_proxy == 'y':
- proxies_queue.put(self.proxy)
- old_proxy = self.proxy
- self.proxy = proxies_queue.get()
- print('task {} new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
- else:
- print('task {} error {}'.format(self.number, ex.__repr__()))
- class Changer:
- __instance = None
- @staticmethod
- def getInstance():
- """ Static access method. """
- if not Changer.__instance:
- Changer()
- return Changer.__instance
- def __init__(self):
- """ Virtually private constructor. """
- if Changer.__instance != None:
- raise Exception("This class is a singleton!")
- else:
- Changer.__instance = self
- self.login = None
- self.password = None
- self.edit_url = "https://www.instagram.com/accounts/edit/"
- self.session = None
- self.edit_post_params = None
- def set_credentials(self, login, password):
- self.login = login
- self.password = password
- def prepare_login(self):
- response = self.session.get("https://www.instagram.com/accounts/login/?hl=en", headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Cache-Control": "max-age=0"
- })
- if (response.status_code == 200):
- self.ajax_token = re.search("\"rollout_hash\":\"(.*?)\"", response.text).group(1)
- self.csrf_token = re.search("\"csrf_token\":\"(.*?)\"", response.text).group(1)
- return self.ajax_token is not None and self.csrf_token is not None
- def login(self, username, password):
- if (not self.prepare_login()):
- print("[-] Failed to fetch CSRF token")
- return False
- self.logged_in = self.session.post("https://www.instagram.com/accounts/login/ajax/", headers={
- "Accept": "*/*",
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/accounts/login/?hl=en",
- "X-CSRFToken": self.csrf_token,
- "X-Instagram-AJAX": self.ajax_token,
- "X-Requested-With": "XMLHttpRequest"
- }, data={
- "username": username,
- "password": password
- }).json()["authenticated"]
- return self.logged_in
- def logout(self):
- self.session.post("https://www.instagram.com/accounts/logout/", headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/{}/".format(self.username)
- }, data={
- "csrfmiddlewaretoken": self.session.cookies["csrftoken"]
- })
- return "sessionid" not in self.session.cookies
- def consent_required():
- response = self.session.post("https://www.instagram.com/web/consent/update_dob/", headers={
- "Accept": "*/*",
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/terms/unblock/?next=/",
- "X-CSRFToken": self.session.cookies["csrftoken"],
- "X-Instagram-AJAX": self.ajax_token,
- "X-Requested-With": "XMLHttpRequest"
- }, data={
- "day": "1",
- "month": "1",
- "year": "1998",
- "current_screen_key": "dob"
- })
- if ("\"status\": \"ok\"" in response.text):
- print("[+] Successfully updated consent to GDPR")
- return self.get_email();
- print("[-] Failed to consent to GDPR, use an IP that is not from Europe")
- return False
- def get_email(self):
- response = self.session.get("https://www.instagram.com/accounts/edit/", headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Referer": "https://www.instagram.com/accounts/login/?next=/accounts/edit/",
- "Cache-Control": "max-age=0"
- })
- if ("/terms/unblock/" in response.url):
- return self.consent_required()
- elif ("/accounts/edit/" in response.url and response.status_code == 200):
- self.email = re.search("\"email\":\"(.*?)\"", response.text).group(1)
- self.username = re.search("\"username\":\"(.*?)\"", response.text).group(1)
- return self.email is not None and self.username is not None
- def username_available(self, username):
- return self.session.get("https://www.instagram.com/{}/?__a=1".format(username), headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Cache-Control": "max-age=0"
- }).status_code == 404
- def set_username(self, username):
- return self.session.post("https://www.instagram.com/accounts/edit/", headers={
- "Accept": "*/*",
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/accounts/edit/",
- "X-CSRFToken": self.session.cookies["csrftoken"],
- "X-Instagram-AJAX": self.ajax_token,
- "X-Requested-With": "XMLHttpRequest"
- }, data={
- "email": self.email,
- "username": username,
- "gender": "3"
- }).status_code == 200
- def change_username(self):
- global CATCH
- try:
- if (self.instagram.username_available(self.target)):
- if (self.instagram.set_username(self.target)):
- print("\r[+]Claimed username @{} after {:,} attempts\n".format(self.target, self.attempts + 1))
- self.terminate()
- if res.status_code == 200:
- CATCH = False
- print('[-]Missed!')
- except Exception as ex:
- print('Change username error {}'.format(ex.__repr__()))
- current_username = input('[!] username: ')
- password = input('[!] password: ')
- target = input('[?] target: ')
- use_proxy = input('Use proxy? (y/n): ')
- threads_count = int(input('Enter threads count: '))
- print('Try login to Instagram \n\n')
- changer = Changer.getInstance()
- changer.set_credentials(current_username, password)
- changer.instagram_login()
- if use_proxy != 'n':
- print('collect proxies from file')
- with open('proxies.txt') as f:
- for proxy in f:
- proxies_queue.put(proxy.rstrip())
- print('{} proxies collected'.format(proxies_queue.qsize()))
- if use_proxy == 'y' and threads_count > proxies_queue.qsize():
- exit('You specified more threads than have proxies')
- loop = asyncio.get_event_loop()
- for i in range(threads_count):
- loop.create_task(Turbo(target, i).start())
- print('{} tasks were created'.format(threads_count))
- loop.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement