302_poc_2.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import json
  2. import logging
  3. import multiprocessing
  4. import random
  5. import re
  6. import threading
  7. import time
  8. import traceback
  9. from datetime import datetime
  10. from urllib import parse
  11. import requests
  12. from tools.utils import get_random_browser, get_proxy_ip, FileWriter
  13. def poc_2(account, passwd, target_url, log_name, single_proxy):
  14. lock = threading.Lock()
  15. with lock:
  16. print('account: %s, passwd: %s' % (account, passwd))
  17. writer = FileWriter(log_name)
  18. writer.write_to_file(f'------{account}, {passwd}------ \n')
  19. user_agent = get_random_browser()
  20. # # 随机数分页
  21. # page = random.randint(1, 5)
  22. # page_size = random.randint(50, 100)
  23. # single_proxy = get_proxy_ip(page, page_size)
  24. # single_proxy = 'rrehqcjf:33f90umk8x32@185.199.228.220:7300'
  25. proxies = {
  26. 'http': f'http://{single_proxy}',
  27. # 'https': 'https://' + single_proxy
  28. }
  29. print('proxies:', proxies)
  30. writer.write_to_file(f'account: {account}, passwd: {passwd}, proxies:{proxies} \n')
  31. # session
  32. """
  33. 模拟登录
  34. """
  35. # 定义请求地址
  36. login_url = "https://t.livepocket.jp/api/sessions/create?mytimestamp=" + str(int(time.time()))
  37. # 定义请求header
  38. headers = {'Content-Type': 'application/x-www-form-urlencoded;',
  39. 'Referer': 'https://t.livepocket.jp/login?acroot=header-new_p_u_nl',
  40. # 'Sec-Ch-Ua': 'Chromium',
  41. 'User-Agent': user_agent
  42. }
  43. # 通过字典方式定义请求body
  44. form_data = {"login": account,
  45. "password": passwd,
  46. "auto_login": "on",
  47. "login_password": f"{account}&{passwd}"
  48. }
  49. data = parse.urlencode(form_data)
  50. session = requests.session()
  51. content = session.post(url=login_url, headers=headers, data=data, proxies=proxies).text
  52. cookie = session.cookies
  53. response_cookie = cookie.get_dict()
  54. login_resp = json.loads(content)
  55. token = login_resp['result']['token']
  56. login_session = response_cookie['ci_session']
  57. php_session = response_cookie['PHPSESSID']
  58. # event_id
  59. event_id = 0
  60. response = requests.get(target_url, proxies=proxies)
  61. if response.status_code == 200:
  62. html_string = response.content.decode('utf8')
  63. start_index = html_string.find('https://t.livepocket.jp/purchase/verify?event_id=')
  64. if start_index != -1:
  65. end_index = html_string.find("'", start_index)
  66. if end_index != -1:
  67. event_id = html_string[start_index + len('https://t.livepocket.jp/purchase/verify?event_id='):end_index]
  68. print(f'event_id: {event_id}')
  69. else:
  70. print('End index not found.')
  71. else:
  72. print('Substring not found.')
  73. else:
  74. print('Failed to fetch the page. Status code:', response.status_code)
  75. # ticket_id
  76. ticket_id = 0
  77. response = requests.get(target_url, proxies=proxies)
  78. if response.status_code == 200:
  79. html_string = response.text
  80. match = re.search(r'id="js_order_limited_(\d+)"', html_string)
  81. if match:
  82. ticket_id = match.group(1)
  83. print(ticket_id)
  84. else:
  85. print("未找到匹配的数值")
  86. # event_cname
  87. # url = 'https://t.livepocket.jp/e/lxyyc'
  88. sub_str = target_url.replace("https://t.livepocket.jp/", "")
  89. strs = sub_str.split('/')
  90. cname = strs[len(strs) - 1]
  91. # print(cname)
  92. # redirect_url1
  93. net_url = 'https://t.livepocket.jp/purchase?type=new'
  94. result = requests.Session()
  95. header = {
  96. 'Host': 't.livepocket.jp',
  97. 'User-Agent': "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
  98. "Chrome/69.0.3947.100 Safari/537.36",
  99. 'Content-Type': 'application/x-www-form-urlencoded',
  100. 'Referer': f'{target_url}',
  101. }
  102. # my_session = 'IN7u3uuP5WcizQkmRzF%2F3OsLuNNQePnxNBvnlPgqT6FPz2BgyKT2KCJaMvdj8ZSa6wNp2xZIL6VoA7Mj0R2zECMZkOKJOLbsNwUdXwvcsROxjfCzibxEaj4nG%2Bq29dCEUdiWI2TgUsKSFGRZaOP0p37ktl%2B1wSMqMAk918Nkt7APIxpQtZ%2BoLwId4PMOkN3oOIwT3CvsuDbgPQHIuokZXcnNe8uOAUuZBLW4nKOdYimLcSw6oTMt85UXkwm4OyTdxYR3%2B8crA0OfQCyfHXqY%2Bj0t9R0mmNSusRXRDuDBmOCFR58vHVuuwZ0AXNHYoYB0sdm28VL9xgHHrzkvm2M9cpLEIVWUWBWGaZgtO3xp2d8L70%2BfAKwyv6JPGcGmGf9wUQzBltssBpMmYqSfkws1%2Bp8BOhmXOqfljSYbWcxxVVSw%2B2dtoxBXsTf793mD9sVYRsrr8YPGz4JPVGWGU0outg%3D%3D'
  103. cookies = {
  104. 'ci_session': f'{login_session}',
  105. 'PHPSESSID': f'{php_session}',
  106. 'list_count': '{"success":true,"result":{"myticket_count":{"count":"0"},"today_event":{"total_count":0,"data_list":[]},"unread_count":5},"submit":true}',
  107. 'sns_status': '{"success":true,"result":{"facebook":0,"twitter":0,"mixi":0,"line":0,"yahoo":0,"plusid":1,"google":0},"submit":true}',
  108. 'display_init': '{"success":true,"result":{"purchased_tickets":{"total_count":0,"data_list":{"ticket_info":[]}},"lottery_tickets":{"total_count":0,"data_list":{"ticket_info":[]}},"order_limited_event_tickets":{"data_list":{"ticket_info":[]},"total_count":0},"event_order_limit":true},"submit":true}',
  109. }
  110. ticket_key = f'ticket_id_{ticket_id}'
  111. form_data = {
  112. 'redirect_url': 'https://t.livepocket.jp/purchase/',
  113. 'event_id': event_id,
  114. 'event_cname': f'{cname}',
  115. 'ticket_type': 'lottery',
  116. 'facebook_ticket_count': 0,
  117. 'twitter_ticket_count': 0,
  118. 'plusid_linkage_invalidation_flg': 0,
  119. ticket_key: 1
  120. }
  121. print('form_data:', form_data)
  122. response = result.post(net_url, headers=header, cookies=cookies, data=form_data, allow_redirects=False,
  123. proxies=proxies)
  124. print('response.headers: ', response.headers)
  125. if 'Location' in response.headers:
  126. redirect_url1 = response.headers['Location']
  127. print('redirect_url1: ', redirect_url1)
  128. else:
  129. return
  130. # https://t.livepocket.jp/purchase/security?id=309887&type=new
  131. # redirect_url2
  132. response2 = result.get(redirect_url1, headers=header, cookies=cookies, allow_redirects=False, proxies=proxies)
  133. print('response2.headers: ', response2.headers)
  134. if 'Location' in response2.headers:
  135. redirect_url2 = response2.headers['Location']
  136. print('redirect_url2: ', redirect_url2)
  137. else:
  138. return
  139. # https://t.livepocket.jp/purchase/confirm?id=309887&reserved_session_id=423272
  140. # redirect_url3
  141. response3 = result.get(redirect_url2, headers=header, cookies=cookies, allow_redirects=False, proxies=proxies)
  142. print('response3.headers: ', response3.headers)
  143. if 'Location' in response3.headers:
  144. redirect_url3 = response3.headers['Location']
  145. print('redirect_url3: ', redirect_url3)
  146. else:
  147. print('redirect_url3 is None')
  148. return
  149. # https://t.livepocket.jp/purchase/confirm?id=309887&reserved_session_id=794986&otoken=mMyZTgzMmQ4OWQ5ZjY5NWFlNGE2ZmJlMWM5Mm
  150. # drawing_tickets
  151. drawing_url = 'https://t.livepocket.jp/api/drawing_tickets/entry?mytimestamp=' + str(int(time.time()))
  152. region_string = redirect_url3.split('?')[1]
  153. params = region_string.split('&')
  154. reserve_session_id = params[1].split("=")[1]
  155. drawing_headers = {
  156. 'Host': 't.livepocket.jp',
  157. 'User-Agent': user_agent,
  158. 'Content-Type': 'application/x-www-form-urlencoded',
  159. 'Referer': f'{redirect_url3}',
  160. }
  161. drawing_cookies = {
  162. 'ci_session': f'{login_session}',
  163. 'PHPSESSID': f'{php_session}',
  164. }
  165. drawing_form_data = {
  166. 'utoken': f'{token}',
  167. 'onetime_token_name': 'buy_ticket',
  168. 'onetime_token_value': params[2].split('=')[1],
  169. 'url': f'https://t.livepocket.jp/purchase/confirm?id={event_id}&reserved_session_id={reserve_session_id}',
  170. 'payment_method': 0,
  171. 'reserve_session_id': reserve_session_id,
  172. 'event_id': event_id,
  173. 'reserve_ticket[0][ticket_id]': ticket_id,
  174. 'reserve_ticket[0][amount]': 1,
  175. 'payment_type': 'credit'
  176. }
  177. drawing_response = result.post(drawing_url, headers=drawing_headers, cookies=drawing_cookies,
  178. data=drawing_form_data, allow_redirects=False, proxies=proxies)
  179. print('drawing_response.text: ', drawing_response.text)
  180. drawing_data = json.loads(drawing_response.text)
  181. if drawing_data['success']:
  182. order_id = drawing_data['result']['order_id']
  183. onetime_token_name = drawing_data['result']['onetime_token_name']
  184. onetime_token_value = drawing_data['result']['onetime_token_value']
  185. print('account, order_id, onetime_token_name, onetime_token_value', account, order_id, onetime_token_name,
  186. onetime_token_value)
  187. writer.write_to_file(
  188. f'account:{account}, order_id:{order_id}, onetime_token_name:{onetime_token_name}, onetime_token_value:{onetime_token_value} \n')
  189. def process_account(account, log_name, single_proxy):
  190. try:
  191. run_poc(account.strip(), 'panyue666', 'https://t.livepocket.jp/e/sakuhana_197', log_name, single_proxy)
  192. except Exception as ex:
  193. print(f'error: {traceback.format_exc()}, account:{account}')
  194. def process_running():
  195. log_name = f"data_{datetime.now().strftime('%Y%m%d%H%M')}.txt"
  196. # 设置日志配置
  197. # logging.basicConfig(filename=log_name, level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
  198. with open('account.txt', 'r') as accounts:
  199. account_list = accounts.readlines()
  200. threads = []
  201. for account in account_list:
  202. # 随机数分页
  203. page = random.randint(1, 5)
  204. page_size = random.randint(10, 50)
  205. single_proxy = get_proxy_ip(page, page_size)
  206. thread = threading.Thread(target=process_account, args=(account, log_name, single_proxy))
  207. threads.append(thread)
  208. thread.start()
  209. for thread in threads:
  210. thread.join()
  211. def run_poc(account, password, url, log_name, single_proxy):
  212. try:
  213. poc_2(account, password, url, log_name, single_proxy)
  214. except Exception as e:
  215. print(f'error: {traceback.format_exc()}, account:{account}')
  216. if __name__ == '__main__':
  217. # 新增下面一行代码即可打包多进程
  218. multiprocessing.freeze_support()
  219. # log_name = f"data_{datetime.now().strftime('%Y%m%d%H%M')}.txt"
  220. # # 设置日志配置
  221. # logging.basicConfig(filename=log_name, level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
  222. # with open('account.txt', 'r') as accounts:
  223. # for account in accounts:
  224. # try:
  225. # poc_2(account.strip(), 'panyue666', 'https://t.livepocket.jp/e/cx591', log_name)
  226. # except Exception as e:
  227. # print(f'error: {e}, account:{account}')
  228. process_running()
  229. # if __name__ == '__main__':
  230. # multiprocessing.freeze_support()
  231. # log_name = f"data_{datetime.now().strftime('%Y%m%d%H%M')}.txt"
  232. #
  233. # # 读取 accounts.txt 文件中的账号数量
  234. # with open('account.txt', 'r') as accounts:
  235. # account_count = sum(1 for _ in accounts)
  236. #
  237. # # 创建线程池
  238. # threads = []
  239. # with open('account.txt', 'r') as accounts:
  240. # for account in accounts:
  241. # account = account.strip()
  242. # t = threading.Thread(target=run_poc,
  243. # args=(account, 'panyue666', 'https://t.livepocket.jp/e/cx591', log_name))
  244. # t.start()
  245. # threads.append(t)
  246. #
  247. # # 如果线程数达到账号数,则等待所有线程执行完毕
  248. # if len(threads) == account_count:
  249. # for t in threads:
  250. # t.join()
  251. # threads.clear()