Python Port Scanner says all ports are closed
Question: I'm decently skilled in python programming and i'm trying to make a port
scanner without using any third party libraries. Below is the code I've
written so far but the problem is that when i scan my laptop's IP address, it
says that all the ports are closed. Is there something wrong with my code or
are all the ports actually closed(if so, why?). Any help will be much
appreciated, thanks.

    
    
    from socket import *
    
    class scanner():
      def __init__(self, ip):
        self.ip = ip
        self.scan()
    
    def scan(self):
        print("Starting scan on host: %s "%(self.ip))
        for i in range(0, 10000):
            s = socket(AF_INET, SOCK_STREAM)
            try:
                s.connect((ip, i))
                print('Port %d: OPEN' % (i))
                s.close()
            except:
                print('Port %d: CLOSED' % (i))
                s.close()
    
    
    ip = input("Input IP address to scan: ")
    scanner(ip)
    


Answer: You need to connect to the ip you're passing into the constructor: instead of:

    
    
     s.connect((ip, i))
    

try:

    
    
     s.connect((self.ip, i))
    

Hope that helps!

