Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.43 KB | None | 0 0
  1. from queue import Queue
  2. import asyncio
  3. import aiohttp
  4. import random
  5. import requests
  6.  
  7.  
  8. CATCH = True
  9.  
  10. proxies_queue = Queue()
  11.  
  12. def indexes():
  13. n = 0
  14. while True:
  15. n += 1
  16. yield str(n)
  17.  
  18.  
  19. counter = indexes()
  20.  
  21.  
  22. class TryAgain(Exception):
  23. pass
  24.  
  25.  
  26. class Turbo:
  27.  
  28. def __init__(self, target, number):
  29. # self.login = login
  30. # self.password = password
  31. self.target = target
  32. self.number = number
  33. self.proxy = None
  34.  
  35.  
  36. async def start(self):
  37. self.proxy = proxies_queue.get() if use_proxy == 'y' else None
  38.  
  39. async with aiohttp.ClientSession() as session:
  40. while CATCH:
  41. try:
  42. res = await session.get('https://www.instagram.com/{0}'.format(self.target),
  43. proxy=self.proxy
  44. )
  45. print('Task: {} Try:{} Target:{} Code:{}'.format(self.number, next(counter), self.target, res.status))
  46.  
  47. if res.status == 404:
  48. changer.change_username()
  49.  
  50. if res.status == 429:
  51. if use_proxy == 'y':
  52. print('task {} is banned. take new proxy'.format(self.number))
  53. old_proxy = self.proxy
  54. proxies_queue.put(self.proxy)
  55. self.proxy = proxies_queue.get()
  56. print('task {} got new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
  57. else:
  58. print('task {} is banned. sleep'.format(self.number))
  59. await asyncio.sleep(60 * 3)
  60. print('task {} waked up. try to make requests')
  61. except Exception as ex:
  62. print('task {} error {} so change proxy'.format(self.number, ex.__repr__()))
  63. # print(await session.get('https://www.google.com/'))
  64. if use_proxy == 'y':
  65. proxies_queue.put(self.proxy)
  66. old_proxy = self.proxy
  67. self.proxy = proxies_queue.get()
  68. print('task {} new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
  69. else:
  70. print('task {} error {}'.format(self.number, ex.__repr__()))
  71.  
  72.  
  73.  
  74. class Changer:
  75. __instance = None
  76.  
  77. @staticmethod
  78. def getInstance():
  79. """ Static access method. """
  80. if not Changer.__instance:
  81. Changer()
  82. return Changer.__instance
  83.  
  84. def __init__(self):
  85. """ Virtually private constructor. """
  86. if Changer.__instance != None:
  87. raise Exception("This class is a singleton!")
  88. else:
  89. Changer.__instance = self
  90. self.login = None
  91. self.password = None
  92. self.edit_url = "https://www.instagram.com/accounts/edit/"
  93. self.session = None
  94. self.edit_post_params = None
  95.  
  96.  
  97. def set_credentials(self, login, password):
  98. self.login = login
  99. self.password = password
  100.  
  101.  
  102. def prepare_login(self):
  103. response = self.session.get("https://www.instagram.com/accounts/login/?hl=en", headers={
  104. "Accept-Language": "en-US,en;q=0.5",
  105. "Accept-Encoding": "gzip, deflate, br",
  106. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  107. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  108. "Cache-Control": "max-age=0"
  109. })
  110.  
  111. if (response.status_code == 200):
  112. self.ajax_token = re.search("\"rollout_hash\":\"(.*?)\"", response.text).group(1)
  113. self.csrf_token = re.search("\"csrf_token\":\"(.*?)\"", response.text).group(1)
  114.  
  115. return self.ajax_token is not None and self.csrf_token is not None
  116.  
  117. def login(self, username, password):
  118. if (not self.prepare_login()):
  119. print("[-] Failed to fetch CSRF token")
  120. return False
  121.  
  122. self.logged_in = self.session.post("https://www.instagram.com/accounts/login/ajax/", headers={
  123. "Accept": "*/*",
  124. "Accept-Language": "en-US,en;q=0.5",
  125. "Accept-Encoding": "gzip, deflate, br",
  126. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  127. "Content-Type": "application/x-www-form-urlencoded",
  128. "Referer": "https://www.instagram.com/accounts/login/?hl=en",
  129. "X-CSRFToken": self.csrf_token,
  130. "X-Instagram-AJAX": self.ajax_token,
  131. "X-Requested-With": "XMLHttpRequest"
  132. }, data={
  133. "username": username,
  134. "password": password
  135. }).json()["authenticated"]
  136.  
  137. return self.logged_in
  138.  
  139. def logout(self):
  140. self.session.post("https://www.instagram.com/accounts/logout/", headers={
  141. "Accept-Language": "en-US,en;q=0.5",
  142. "Accept-Encoding": "gzip, deflate, br",
  143. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  144. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  145. "Content-Type": "application/x-www-form-urlencoded",
  146. "Referer": "https://www.instagram.com/{}/".format(self.username)
  147. }, data={
  148. "csrfmiddlewaretoken": self.session.cookies["csrftoken"]
  149. })
  150.  
  151. return "sessionid" not in self.session.cookies
  152.  
  153. def consent_required():
  154. response = self.session.post("https://www.instagram.com/web/consent/update_dob/", headers={
  155. "Accept": "*/*",
  156. "Accept-Language": "en-US,en;q=0.5",
  157. "Accept-Encoding": "gzip, deflate, br",
  158. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  159. "Content-Type": "application/x-www-form-urlencoded",
  160. "Referer": "https://www.instagram.com/terms/unblock/?next=/",
  161. "X-CSRFToken": self.session.cookies["csrftoken"],
  162. "X-Instagram-AJAX": self.ajax_token,
  163. "X-Requested-With": "XMLHttpRequest"
  164. }, data={
  165. "day": "1",
  166. "month": "1",
  167. "year": "1998",
  168. "current_screen_key": "dob"
  169. })
  170.  
  171. if ("\"status\": \"ok\"" in response.text):
  172. print("[+] Successfully updated consent to GDPR")
  173. return self.get_email();
  174.  
  175. print("[-] Failed to consent to GDPR, use an IP that is not from Europe")
  176. return False
  177.  
  178. def get_email(self):
  179. response = self.session.get("https://www.instagram.com/accounts/edit/", headers={
  180. "Accept-Language": "en-US,en;q=0.5",
  181. "Accept-Encoding": "gzip, deflate, br",
  182. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  183. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  184. "Referer": "https://www.instagram.com/accounts/login/?next=/accounts/edit/",
  185. "Cache-Control": "max-age=0"
  186. })
  187.  
  188. if ("/terms/unblock/" in response.url):
  189. return self.consent_required()
  190. elif ("/accounts/edit/" in response.url and response.status_code == 200):
  191. self.email = re.search("\"email\":\"(.*?)\"", response.text).group(1)
  192. self.username = re.search("\"username\":\"(.*?)\"", response.text).group(1)
  193.  
  194. return self.email is not None and self.username is not None
  195.  
  196. def username_available(self, username):
  197. return self.session.get("https://www.instagram.com/{}/?__a=1".format(username), headers={
  198. "Accept-Language": "en-US,en;q=0.5",
  199. "Accept-Encoding": "gzip, deflate, br",
  200. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  201. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  202. "Cache-Control": "max-age=0"
  203. }).status_code == 404
  204.  
  205. def set_username(self, username):
  206. return self.session.post("https://www.instagram.com/accounts/edit/", headers={
  207. "Accept": "*/*",
  208. "Accept-Language": "en-US,en;q=0.5",
  209. "Accept-Encoding": "gzip, deflate, br",
  210. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  211. "Content-Type": "application/x-www-form-urlencoded",
  212. "Referer": "https://www.instagram.com/accounts/edit/",
  213. "X-CSRFToken": self.session.cookies["csrftoken"],
  214. "X-Instagram-AJAX": self.ajax_token,
  215. "X-Requested-With": "XMLHttpRequest"
  216. }, data={
  217. "email": self.email,
  218. "username": username,
  219. "gender": "3"
  220. }).status_code == 200
  221.  
  222.  
  223. def change_username(self):
  224.  
  225. global CATCH
  226.  
  227. try:
  228. if (self.instagram.username_available(self.target)):
  229. if (self.instagram.set_username(self.target)):
  230. print("\r[+]Claimed username @{} after {:,} attempts\n".format(self.target, self.attempts + 1))
  231. self.terminate()
  232. if res.status_code == 200:
  233. CATCH = False
  234. print('[-]Missed!')
  235. except Exception as ex:
  236. print('Change username error {}'.format(ex.__repr__()))
  237.  
  238.  
  239.  
  240. current_username = input('[!] username: ')
  241. password = input('[!] password: ')
  242. target = input('[?] target: ')
  243. use_proxy = input('Use proxy? (y/n): ')
  244. threads_count = int(input('Enter threads count: '))
  245.  
  246.  
  247. print('Try login to Instagram \n\n')
  248. changer = Changer.getInstance()
  249. changer.set_credentials(current_username, password)
  250. changer.instagram_login()
  251.  
  252.  
  253. if use_proxy != 'n':
  254. print('collect proxies from file')
  255.  
  256. with open('proxies.txt') as f:
  257. for proxy in f:
  258. proxies_queue.put(proxy.rstrip())
  259.  
  260. print('{} proxies collected'.format(proxies_queue.qsize()))
  261.  
  262.  
  263. if use_proxy == 'y' and threads_count > proxies_queue.qsize():
  264. exit('You specified more threads than have proxies')
  265.  
  266.  
  267. loop = asyncio.get_event_loop()
  268.  
  269. for i in range(threads_count):
  270. loop.create_task(Turbo(target, i).start())
  271.  
  272.  
  273. print('{} tasks were created'.format(threads_count))
  274. loop.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement