I needed to do a minimal tcp server to check if I was able to connect to that host from another machine. I found out that I did not have any nc (NetCat) available on the machine, and no working repo for the machine either.
So I wanted to setup a small tcp listener that wasn’t nc based. I guess I could have used nc -l 443 for the same task if it was available on the system.
HOST = '' # Symbolic name, meaning all available interfaces
PORT = 443 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
#Bind socket to local host and port
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg) + ' Message ' + msg
print 'Socket bind complete'
#Start listening on socket
print 'Socket now listening'
#now keep talking with the client
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr + ':' + str(addr)
Setup of port knocking to let networking guys get something to sniff for while I do other stuff:
[user@host1 ~]$ while true; do date ; echo trying... ; nc imap.mailserver.tld 143 -w 10; sleep 50; done
Tue Oct 3 08:53:10 CEST 2017
Tue Oct 3 08:54:10 CEST 2017
Tue Oct 3 08:55:10 CEST 2017
Tue Oct 3 08:56:10 CEST 2017
Tue Oct 3 08:57:10 CEST 2017
Tue Oct 3 08:58:10 CEST 2017
Tue Oct 3 08:59:10 CEST 2017