Python - No connection could be made because the target machine actively refused it
<p>I'm new in Python and I'm trying to execute this piece of code importing Socket:</p>

<pre><code>import socket
def retBanner(ip, port):
    try:
        socket.setdefaulttimeout(2)
        s = socket.socket()
        s.connect((ip,port))
        banner = s.recv(1024)
        return banner
    except Exception as e:
        return str(e)

def main():
    ip1 = '10.0.0.12'
    ip2 = '10.0.0.11'
    port = 21

banner1 = retBanner(ip1, port)
if banner1:
    print('[+] ' + ip1 + ': ' + banner1)

banner2 = retBanner(ip2, port)
if banner2:
    print("[+] " + ip2 + ': ' + banner2)

if __name__ == '__main__':
    main()
</code></pre>

<p>Even if I just try in shell,</p>

<pre><code>&gt;&gt;&gt; import socket
&gt;&gt;&gt; socket.setdefaulttimeout(2)
&gt;&gt;&gt; s = socket.socket()
&gt;&gt;&gt; s.connect(("10.0.0.12",21))
</code></pre>

<p>it throws the following Exception</p>

<pre><code>[+] 10.0.0.12: [WinError 10061] No connection could be made because the target machine actively refused it
</code></pre>

<p>I'd like to know why, I have my Firewalls off..</p>

<p>Greetings!</p>