我使用后面的代码进行端口扫描。主要问题和其他问题如下:
为什么下面标题为主要问题的部分没有读取ACK数据包? 如果港口正在发放横幅或者我必须发送特定的东西,发送任何东西会产生横幅吗? (见第二个问题)
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()
答案 0 :(得分:0)
//I WAS HOPING THIS WOULD READ ACK PACKETS results = connSkt.recv(100)
为什么你会这么想? (a)您尚未发送任何内容,因此无需确认,并且(b)套接字API不会将ACK数据包返回给应用程序。它们在TCP堆栈中处理。
//SECOND QUESTION //I WAS HOPING THIS WOULD RESULT IN A BANNER sock.send("Doesntmatter\r\n")
同样,你为什么期待呢?发送数据不会产生横幅。您必须接收某些东西,而且似乎是横幅,这意味着对等应用程序必须发送横幅,其中大部分都没有。