Last active
July 17, 2023 07:20
-
-
Save we684123/522070ce07a451d9f146068e0873df7f to your computer and use it in GitHub Desktop.
掃 ip 下的 ssh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import threading | |
def check_ssh(ip, port=22): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.settimeout(3) | |
try: | |
sock.connect((ip, port)) | |
sock.close() | |
return True | |
except socket.error: | |
return False | |
def scan_ip(ip): | |
if check_ssh(ip): | |
print(f'SSH 已開啟在 {ip}') | |
threads = [] | |
for i in range(1, 256): | |
ip = f'192.168.5.{i}' | |
thread = threading.Thread(target=scan_ip, args=(ip,)) | |
thread.start() | |
threads.append(thread) | |
# 等待所有線程完成 | |
for thread in threads: | |
thread.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment