show_ip.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #import redis
  2. import time
  3. import traceback
  4. #import json
  5. from selenium import webdriver
  6. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  7. import time
  8. import os
  9. from selenium.webdriver.support.ui import WebDriverWait
  10. from selenium.webdriver.common.by import By
  11. from selenium.webdriver.support import expected_conditions as EC
  12. import dataset
  13. from selenium.webdriver.common.keys import Keys
  14. import json
  15. import random
  16. import time
  17. import redis
  18. import sys
  19. import codecs
  20. import random
  21. import os
  22. import time
  23. from userAgentRandomizer import userAgents
  24. import requests
  25. driver=None
  26. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  27. headers = {
  28. "Authorization": "Bearer " + "6SDULL1Ebklduc6TFxa97AFto5Sj21kyJ30CxiLiSoi",
  29. "Content-Type": "application/x-www-form-urlencoded"
  30. }
  31. def send_msg(kw):
  32. params = {"message":kw}
  33. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
  34. def re_get_webdriver():
  35. global port
  36. global driver
  37. result=[]
  38. if driver is not None:
  39. print('closing....')
  40. driver.quit()
  41. os.system('killall chrome')
  42. print('quit....')
  43. driver=None
  44. try:
  45. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  46. data=r.get('google_proxy')
  47. jstext=data.decode('utf-8')
  48. jsobj=json.loads(jstext)
  49. print(jsobj)
  50. proxy=random.choice(jsobj)
  51. ua = userAgents()
  52. user_agent = ua.random()
  53. options = webdriver.ChromeOptions()
  54. options.add_argument("--no-sandbox")
  55. options.add_argument("--disable-dev-shm-usage")
  56. options.add_argument("--headless")
  57. # options.add_argument('--remote-debugging-port='+port)
  58. options.add_argument('--proxy-server='+proxy)
  59. # options.add_argument('--proxy-server=socks5://192.53.174.202:8180')
  60. # options.add_argument('--proxy-server=%s' % proxy)
  61. print(proxy)
  62. # print('--proxy-server=%s' % proxy)
  63. # options.add_experimental_option("debuggerAddress", '127.0.0.1:9922')
  64. print(user_agent)
  65. # options.add_argument("--user-agent=" +user_agent)
  66. options.add_argument("--incognito")
  67. driver=None
  68. try:
  69. # driver = webdriver.Chrome(options=options)
  70. if os.name=='nt':
  71. driver = webdriver.Chrome(executable_path='C:/portable/webdriver/chrome102/chromedriver.exe',options=options)
  72. else:
  73. # driver = webdriver.Remote(
  74. # executable_path='/root/drivers/102/chromedriver',
  75. # command_executor='http://0.0.0.0:4444/wd/hub',
  76. # options=options
  77. # )
  78. # driver = webdriver.Chrome(executable_path='/root/drivers/102/chromedriver',options=options)
  79. driver = webdriver.Chrome(options=options)
  80. except:
  81. # driver.quit()
  82. # os.system('pkill -f ')
  83. # os.system('kill %d' % os.getpid())
  84. traceback.print_exc()
  85. sys.exit()
  86. return
  87. driver.set_window_size(1400,1000)
  88. return
  89. except:
  90. traceback.print_exc()
  91. driver=None
  92. return None
  93. def run_once(jsobj):
  94. table=db['rank_detection']
  95. print(jsobj)
  96. global driver
  97. # i=random.randint(0,9)
  98. i=100
  99. if driver is None:
  100. time.sleep(8)
  101. re_get_webdriver()
  102. if driver is None:
  103. return
  104. try:
  105. kw=jsobj['kw']
  106. if jsobj.get('domain') is None:
  107. exclude=jsobj['exclude']
  108. domain=None
  109. else:
  110. domain=jsobj['domain']
  111. exclude=None
  112. # driver.get('https://www.google.com?num=100')
  113. driver.get('https://api.ipify.org/')
  114. time.sleep(5)
  115. print(driver.current_url)
  116. elmt = driver.find_element(By.XPATH, "//body")
  117. print(elmt.text)
  118. except:
  119. print('exception')
  120. traceback.print_exc()
  121. driver.quit()
  122. sys.exit()
  123. par1='tiny3'
  124. port='9942'
  125. #os.system('docker container restart tiny3')
  126. #time.sleep(8)
  127. #os.system('docker exec -it tiny3 curl --socks5 choozmo:choozmo9@172.105.205.52:8180 http://www.google.com')
  128. #p=random.choice(positive)
  129. run_once({'domain':'test','kw':" ttes"})
  130. #run_once({'domain':domain,'kw':kw+' 錢濤'})