заменил localhost на 0.0.0.0 и всё работает.
Using username "root".
Authenticating with public key "imported-openssh-key"
Linux v43195 4.9.0-16-amd64 #1 SMP Debian 4.9.272-2 (2021-07-19) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@v43195:~# python3
Python 3.7.2 (default, Oct 10 2020, 15:44:37)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>>
>>> listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>>> listener.bind(('0.0.0.0', 9999))
>>> listener.listen(0)
>>> print("Wait")
Wait
>>> listener.accept()
(<socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('46.17.45.71', 9999), raddr=('5.101.156.100', 56353)>, ('5.101.156.100', 56353))
>>> print("Connect")
Connect
>>>
Using username "x90048bt".
Pre-authentication banner message from server:
| Welcome to LTD BeGet SSH Server 'bigbone'
End of banner message from server
Authenticating with public key "imported-openssh-key"
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 4.9.207-1-beget-acl x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sun Jan 2 18:58:44 2022 from 85.249.21.110
x90048bt@bigbone:~ [0] $ python
Python 2.7.3 (default, Oct 26 2016, 21:01:49)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> connection.connect(('46.17.45.71', 9999))
>>> connection.close()
>>>