API to get your public IP and other HTTP request metadata
Often times we face the need to get our public IP address; in doing so, from time to time, we've used many URL endpoints, found in the wild - which seem to serve well for a while before disappearing suddenly, forever. As a permanent fix to this dilemma, i've written a tiny app and created couple of URL endpoints on my BookShelfBD.com
domain to get the public IP address and some HTTP request metadata over HTTP.
Currently, i've exposed two endpoints:
-
/public/ip/
: To get the public IP address -
/public/meta/
: To get a few HTTP request metadata
The output will be in json
for scalability.
Here is a curl
workflow:
% curl https://bookshelfbd.com/public/ip/ {"client_ip": "119.30.45.193"} % curl https://bookshelfbd.com/public/meta/ {"client_ip": "119.30.45.193", "client_port": "50111", "http_protocol": "HTTP/1.1", "request_method": "GET", "user_agent": "curl/7.47.0"}
Taking help from jq
to prettify the json
output:
% curl -s https://bookshelfbd.com/public/ip/ | jq . { "client_ip": "119.30.45.193" } % curl -s https://bookshelfbd.com/public/meta/ | jq . { "client_ip": "119.30.45.193", "client_port": "50115", "http_protocol": "HTTP/1.1", "request_method": "GET", "user_agent": "curl/7.47.0" }
Comments
Comments powered by Disqus