Skip to content

Category

Developer guides

Developer guides to getting an IP address in code, from cURL and the command line to JSON APIs, Python, JavaScript and Node.js, with copy-ready examples.

All developer tools articles

5 articles

Overview

Getting an IP address in code

These guides are for when you need an IP address inside a script, a server or a CI job rather than on a web page. Every example is short enough to copy, and each one says where the address really comes from, because a machine can only see its public IP by asking something outside its network.

For shell scripts, finding your IP from the command line covers cURL, wget, HTTPie and PowerShell, plus aliases and a small automation script. Getting your IP as JSON and using a JSON API for geolocation show how to read the response in Bash, Node.js, Python, Go and PHP, with timeouts, caching and a fallback for production.

In application code, the Python guide shows requests, the standard library urllib and a plain-text call, and the JavaScript guide explains why the browser has to ask an outside service for the public IP, and how to read the real client address on the server behind proxies and CDNs.

The free endpoints used in the examples are documented on the IP API page: plain text, JSON, XML and YAML, no key needed.