Skip to content

Commit

Permalink
修改为进程池执行 不再获取代理 垃圾代理
Browse files Browse the repository at this point in the history
  • Loading branch information
Degree-21 committed Aug 27, 2020
1 parent a7d7c2a commit a2b89ed
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/dirScan.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions DirScan.py
Expand Up @@ -4,6 +4,7 @@
import threading
import random
import re
import multiprocessing
from Log import set_log


Expand Down Expand Up @@ -45,17 +46,23 @@ def get_all_scan_key(self):
self.queues.put(res)
return

# 多线程扫描
# 多进程扫描
def scan_dir_helps(self):
print("""
扫描进程创建中........
""")
pool = multiprocessing.Pool(processes=3)
list_scan = []
self.get_all_scan_key()
while self.queues.qsize() > 0:
while threading.active_count() < self.limit:
key = self.queues.get()
threads = threading.Thread(target=self.scan_dir, args=(key,))
threads.start()
# while threading.active_count() < self.limit:
key = self.queues.get()
print(key)
list_scan.append(pool.apply_async(self.scan_dir(key)))
# , args = (key,)
pool.join()
# threads = threading.Thread(target=self.scan_dir, args=(key,))
# threads.start()

# 扫描
def scan_dir(self, key):
Expand All @@ -64,14 +71,15 @@ def scan_dir(self, key):
else:
host_addr = self.scan_host_name + '/' + key

keys = random.choice(list(self.ip_list))
port_str = keys + ':' + self.ip_list[keys]
proxies = {
'http': port_str
}

# keys = random.choice(list(self.ip_list))
# port_str = keys + ':' + self.ip_list[keys]
# proxies = {
# 'http': port_str
# }
try:
r = requests.get(url=host_addr, headers=self.get_user_agent(), proxies=proxies)
# r = requests.get(url=host_addr, headers=self.get_user_agent(), proxies=proxies)
r = requests.get(url=host_addr, headers=self.get_user_agent())
print (r)
if r.status_code in self.scan_code:
# 写日志
msg = {host_addr: r.status_code}
Expand All @@ -81,10 +89,7 @@ def scan_dir(self, key):
print(msg)
return msg
except Exception as e:
print(host_addr, '打开失败 !')
# print(host_addr, "无法访问")
# except requests.exceptions.HTTPError as e:
# print("代理ip无法链接")
print(host_addr, "无法访问")

@staticmethod
def get_user_agent():
Expand Down
Binary file modified __pycache__/Log.cpython-37.pyc
Binary file not shown.

0 comments on commit a2b89ed

Please sign in to comment.