Skip to content

Instantly share code, notes, and snippets.

@jbfuzier
Created July 4, 2024 11:02
Show Gist options
  • Save jbfuzier/e109ac5013e9f0b9d287c73ed05953f6 to your computer and use it in GitHub Desktop.
Save jbfuzier/e109ac5013e9f0b9d287c73ed05953f6 to your computer and use it in GitHub Desktop.
Grab SSH Banner
# !/usr/bin/python
import socket
import json
import re
import time
import random
from multiprocessing import Pool, TimeoutError
socket.setdefaulttimeout(4)
def grab_banner(ip_address, port):
ip_address = ip_address.strip()
#print(ip_address)
time.sleep(random.randint(0, 1000) / 1000)
for i in range(2):
try:
s = socket.socket()
s.connect((ip_address, port))
banner = s.recv(1024)
s.close()
return banner
except socket.gaierror:
if i == 1:
return b'dnsfail'
except socket.timeout:
if i == 1:
return b'timeout'
i += 1
time.sleep(random.randint(100, 2000)/1000)
if __name__ == '__main__':
// Load IPS
ips = []
results = []
with Pool(processes=50) as pool:
for ip in ips:
results.append( ( pool.apply_async(grab_banner, (ip, 22)), ip) )
if len(results) == 50:
for r in results:
print("%s;%s"%(r[1], r[0].get()))
results = []
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment