During network connectivity troubleshooting, one thing that always pops up is the need to test connectivity for certain ports, for example, to check if a firewall is blocking a certain port,
I usually spin up a port on a server using either Netcat or Python, ie
while true ; do nc -l -p 8300 -c 'echo -e "HTTP/1.1 200 OK\n\ $(date)"' ; done
using Python2
python -m SimpleHTTPServer 8330
But what if you need to open this port on a particluar network interface? You can do something like this:
python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(("192.168.20.10", 8330), shs.SimpleHTTPRequestHandler).serve_forever()'
or again, the amazing Netcat swiss army knife
nc -l 192.168.20.10 8330
I wanted to replicate the simple Netcat utility using Python, but make it even more easier syntax-wise, while also giving it the ability to bind to network interface names, rather than IP address
Portela
Portela is a simple port listener that is Python 2/3 compatible.
It has zero dependencies.
You can replicate netcat functionality but also have the ability to bind to interfaces using names, and daemonize the process.
Installation
pip install portela
Usage
portela 1234 // spin up a listener on port 1234portela 1234 -i eth1 // spins up on port 1234 on interface ‘eth1’portela 1234 -i eth1 -d // spins up on port 1234 on interface ‘eth1’ and run as daemonportela 1234 -m “samba magic” // spins up on port 1234 and return a message on HTTP callportela stop // stops all instances of portela listenerportela status // check if portela is running as daemonportela help / -h / — help // prints this message
Give it a try.