- Go 42%
- Python 38.6%
- Dockerfile 19.4%
᛫ Added info about the Go version. Signed-off-by: Victor-ray, S. <git@zendai.net.eu.org> |
||
|---|---|---|
| .zed | ||
| Go | ||
| Python | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
Checkport
This is a simple microservice I made for NextcloudPi to check if the port-forwarding has been done properly and the device is reachable from outside the network, then respond with a message saying they are open or closed.
It does this by trying to open a socket connection to port 80 & 443 on the client IP that is connecting with a GET request on the /check endpoint.
It is currently deployed on my personal account at Fly using their free tier and limits. The deployed version can be found under the tag deployed.
There are currently 2 version, one made in Go and one made in Python.
Returns a JSON response with the following information:
| Key | Content |
|---|---|
80 |
open | closed |
443 |
open | closed |
Go
Run with: go run main.go
Build with: go build -o portcheck .
Build with Docker: docker build . -t <nametag>
Run with Docker
docker pull zendai/checkport:go
docker run --rm --detach --publish 8080:8080 zendai/checkport:go
Python
Create a virtual environment
python -m venv venv
# OR
uv venv
Activate the virtual environment
source .venv/bin/activate
Install sanic with
pip install -r requirements.txt
# OR
uv pip install -r requirements.txt
Run it locally
The config for the client IP header is set to Fly-Client-IP which is the name fly.io use for the client IP in their proxy.
It will fall back on the request's IP field if the proxy header is empty.
Run with
sanic server:app --dev -p 8080
If you omit -p 8080 it will default to port 8000 when running sanic with the --dev flag.
Example
A GET request to the /check endpoint.
curl --silent https://localhost:8080/check
Receives the following response.
{
"80": "closed",
"443": "closed"
}
You can test it using netcat or socat and start a listener on both or one of port 80 & 443.
You may need to allow TCP traffic if you have an active firewall blocking incoming traffic
curl -s localhost:8080/check # 80 & 443
# Outputs ↓
{"80":"open","443":"open"}
If you want to deploy one yourself as a Docker image you can build one using the Dockerfile, otherwise you need to install the dependencies in the requirements.txt file.
# $USERNAME: Username at the Docker Hub image registry
# $REPOSITORY: Repository at the Docker Hub image registry
# $IMAGE_TAG: The tag for the image
docker build . -t "$USERNAME/$REPOSITORY:$IMAGE_TAG"
Or if you want to use the one I've built and deployed.
docker pull zendai/checkport:sanic
docker run --rm --detach --publish 8080:8080 zendai/checkport:sanic
If you want to try it out when running it via docker then use your ip-address instead of localhost.