2

I'm new in Python and I'm trying to execute this piece of code importing Socket:

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()

Even if I just try in shell,

>>> import socket
>>> socket.setdefaulttimeout(2)
>>> s = socket.socket()
>>> s.connect(("10.0.0.12",21))

it throws the following Exception

[+] 10.0.0.12: [WinError 10061] No connection could be made because the target machine actively refused it

I'd like to know why, I have my Firewalls off..

Greetings!

  • `banner1 = retBanner(ip1, port)` , banner2 = retBanner(ip2, port) hold on, your accessing level don't allowed `RAW style TCP connection` . `.11 and .12` is same machine but same interface ? Another point is port `21` not meaning `Blackjack` , it's global port, published as FTP port, need close all app(which used port 21) and running as root ! – dsgdfg Dec 23 '16 at 05:46

2 Answers2

2

WinError 10061 - means that the server side TCP is not accepting the connection. For there is no application above listening on that port that client is trying to connect. Please check if you have your server application started and that it is listening on the intended port.

Prabhu
  • 3,443
  • 15
  • 26
0

A viable solution, or maybe rather a workaround, is the following:

Set your default VS-Code internal terminal profile to Command Prompt: enter image description here

For more details, please refer to this full answer.

Andreas L.
  • 3,239
  • 5
  • 26
  • 65