I'm using the code that follows to port scan. The main question and additional questions are as follows:
Why doesn't the part titled main question below read ACK packets? Would sending anything result in a banner if the port was handing out banners or do I have to send something specific? (See Second Question)
import threading
import socket
from socket import *
def scan(ip, port, banners):
try:
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((ip, port))
//MAIN QUESTION
//I WAS HOPING THIS WOULD READ ACK PACKETS
results = connSkt.recv(100)
//SECOND QUESTION
//I WAS HOPING THIS WOULD RESULT IN A BANNER
sock.send("Doesntmatter\r\n")
print(results)
banners[i] = results
sock.close()
except:
pass
def main():
ip = "74.125.224.72"
banners = dict()
setdefaulttimeout(1)
for ports in range(1,1000):
t = threading.Thread(target=scan, args=(ip, int(ports), banners))
t.start()
for keys in banners:
print("Port: " + keys + "\n" + "Banner: " + banners[keys])
exit(0)
main()
1 Answer 1
//I WAS HOPING THIS WOULD READ ACK PACKETS results = connSkt.recv(100)
Why did you expect that? (a) You haven't sent anything yet, so there is nothing to ACK, and (b) the Sockets API doesn't return ACK packets to the application. They are dealt with within the TCP stack.
//SECOND QUESTION //I WAS HOPING THIS WOULD RESULT IN A BANNER sock.send("Doesntmatter\r\n")
Again, why did you expect that? Sending data doesn't result in a banner. You would have to receive something, and that seem thing would have to be a banner, which means the peer application would have to send a banner, which most of them don't do.
nmap?