Skip to content

Instantly share code, notes, and snippets.

@we684123
Last active July 17, 2023 07:20
Show Gist options
  • Save we684123/522070ce07a451d9f146068e0873df7f to your computer and use it in GitHub Desktop.
Save we684123/522070ce07a451d9f146068e0873df7f to your computer and use it in GitHub Desktop.
掃 ip 下的 ssh
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