Banner Grabbing for all tcp ports

Hello friends,
I’ve been trying to write a script to capture banner from any tcp ports but the problem is for some ports it can grab the banner and for some not, like port 53 and others. I know there are programs out there which can do it well but I wan to know how to write it myself,
there must be more than just sending something and wait for the response, right !
thanks in advance.

import socket
import sys
import time
host="X.X.X.X"
port=53
try:
	s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
except socket.error as er:
	print("Error creating",er)	
	sys.exit()
try:
	s.settimeout(3)
	s.connect((host,port))
	s.send(b"Sup")
	data=s.recv(4096)
	print('--> ', format(data))
	s.close()
except socket.error as e:
	print("error -->",e)

Hello, i will make a video covering this today.

2 Likes

Thank you much my brother, can’t wait to see it.