-1

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()
asked Jun 21, 2014 at 7:52
3
  • Oh dear. AFAIK you cannot read low-level packet details with Python. At best you can set the socket into RAW mode but I'm not even sure this would suffice. What's wrong with nmap? Commented Jun 21, 2014 at 8:07
  • Nothing. Just learning and messing around with things. Thanks. Commented Jun 21, 2014 at 8:11
  • See: stackoverflow.com/questions/20203549/using-raw-socket-in-python -- What you are trying to learn is not trivial. Commented Jun 21, 2014 at 8:36

1 Answer 1

0
 //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.

answered Jun 22, 2014 at 22:24
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.