| |
| |
| from queue import Queue |
| import nmap |
| import threading |
| import requests |
| import chardet |
| import re |
| import json |
| import os |
| |
| |
| final_domains = [] |
| |
| |
| ports = [] |
| |
| |
| glock = threading.Lock() |
| |
| |
| |
| class PortScan(threading.Thread): |
| def __init__(self, queue): |
| threading.Thread.__init__(self) |
| self._queue = queue |
| |
| |
| def run(self): |
| while not self._queue.empty(): |
| scan_ip = self._queue.get() |
| glock.acquire() |
| try: |
| self.portscan(scan_ip) |
| self.Scan(scan_ip) |
| except Exception as e: |
| print(e) |
| pass |
| glock.release() |
| |
| |
| |
| def portscan(self, scan_ip): |
| temp_ports = [] |
| os.system('masscan.exe ' + scan_ip + ' -p 1-100 -oJ masscan.json --rate 2000') |
| |
| |
| with open('masscan.json', 'r') as f: |
| for line in f: |
| if line.startswith('{ '): |
| temp = json.loads(line[:-2]) |
| temp_ports.append(str(temp["ports"][0]["port"])) |
| |
| print(temp_ports) |
| |
| if len(temp_ports) > 25: |
| temp_ports.clear() |
| else: |
| ports.extend(temp_ports) |
| |
| |
| |
| def Title(self,scan_url_port, service_name): |
| try: |
| resp = requests.get(scan_url_port, timeout=3, verify=False) |
| |
| detectencode = chardet.detect(resp.content) |
| response = re.findall(r'<title>(.*?)</title>', resp.content.decode(detectencode['encoding']), re.S) |
| if response: |
| |
| |
| res = response[0] |
| banner = resp.headers['server'] |
| final_domains.append(scan_url_port + '\t' + banner + '\t' + res) |
| else: |
| final_domains.append(scan_url_port + '\t' + service_name + '\t' + "获取标题失败,请手动尝试!!!") |
| except: |
| pass |
| |
| |
| |
| def Scan(self,scan_ip): |
| nm = nmap.PortScanner() |
| try: |
| for port in ports: |
| ret = nm.scan(scan_ip, port, arguments='-Pn -sS') |
| service_name = ret['scan'][scan_ip]['tcp'][int(port)]['name'] |
| print('[*] 主机 ' + scan_ip + ' 的 ' + str(port) + ' 端口服务为: ' + service_name) |
| if 'http' in service_name or service_name == 'sun-answerbook': |
| if service_name == 'https' or service_name == 'https-alt': |
| scan_url_port = 'https://' + scan_ip + ':' + str(port) |
| self.Title(scan_url_port, service_name) |
| else: |
| scan_url_port = 'http://' + scan_ip + ':' + str(port) |
| self.Title(scan_url_port, service_name) |
| else: |
| |
| final_domains.append(scan_ip + ':' + str(port) + '\t端口服务为: ' + service_name) |
| except Exception as e: |
| print(e) |
| pass |
| ports.clear() |
| |
| |
| |
| def main(): |
| queue = Queue(1000) |
| try: |
| f = open('ip.txt', 'r') |
| for line in f.readlines(): |
| final_ip = line.strip('\n') |
| queue.put(final_ip) |
| print("加入队列---->" + final_ip) |
| threads = [] |
| thread_count = 50 |
| for i in range(thread_count): |
| threads.append(PortScan(queue)) |
| for t in threads: |
| t.start() |
| for t in threads: |
| t.join() |
| f.close() |
| |
| except: |
| pass |
| |
| |
| if __name__ == '__main__': |
| main() |
| tmp_domians = [] |
| for tmp_domain in final_domains: |
| if tmp_domain not in tmp_domians: |
| tmp_domians.append(tmp_domain) |
| for url in tmp_domians: |
| with open('scan_url_port.txt', 'a') as ff: |
| ff.write(url+'\n') |
参考文章:https://www.freebuf.com/sectool/204578.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY