My initial solution was to run a basic server at the chosen port and execute a lambda function (or Google's Cloud Function -- basically an external API call) that checks if the port is accessible from outside and returns true/false.
But now that I started actually working on it, I am thinking can I skip the external API altogether by using the IP of the same machine??
This is the flow (let me assume I want to check if port 222 was accessible and not blocked by any security group/ISP):
- Start a basic server
nc -l 222
- Get the external IP
IP=$(curl --silent icanhazip.com)
- Try connecting to the port
nc -N $IP 222 < /dev/null
- Check if that was successful
echo $?
So basically in step 3 I did not use an API call to a lambda function that checks port from an external server. I am using the same server but using the external IP.
My question is, will this work in all cases?? Is it good enough? I mean I still feel writing an API will be foolproof but I am curious if I use the IP will the call go through the internet and come back (and doesn't change to localhost at DNS resolution)??
No comments:
Post a Comment