https://github.com/avaray/gip
Get your public IPv4 address
https://github.com/avaray/gip
address cli dependency-free echo external-ip fetch fetch-api iot ip ipv4 network npm npm-module npm-package npmjs
Last synced: 5 months ago
JSON representation
Get your public IPv4 address
- Host: GitHub
- URL: https://github.com/avaray/gip
- Owner: Avaray
- License: mit
- Created: 2022-04-20T17:28:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-16T15:23:21.000Z (over 1 year ago)
- Last Synced: 2025-06-30T13:04:26.183Z (12 months ago)
- Topics: address, cli, dependency-free, echo, external-ip, fetch, fetch-api, iot, ip, ipv4, network, npm, npm-module, npm-package, npmjs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/gip
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: funding.yml
- License: LICENSE
Awesome Lists containing this project
README
# 🐷 GIP (Get IP)
Dependency-free, [TypeScript](https://www.typescriptlang.org/)-friendly module and
[CLI](https://en.wikipedia.org/wiki/Command-line_interface) tool that uses the
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to retrieve your real public
[IPv4](https://en.wikipedia.org/wiki/IPv4) address from "IP echo" services. It fetches data concurrently from multiple services to provide
accurate results as quickly as possible. By default, **GIP** verifies the IP address by waiting for three matching responses from different
services, and you can customize this number using the `ensure` option.
**GIP** uses more than 20 different "IP echo" websites, and you can add your own with the `services` option. Because these services are
external, their availability and reliability may vary. You can reduce risk by choosing a sensible `ensure` count.
## Requirements
[NodeJS](https://nodejs.org/en/download) version **20.0.0** or higher.
## [Module](https://nodejs.org/api/esm.html#modules-ecmascript-modules) installation
[NPM](https://docs.npmjs.com/cli/v10/commands/npm-install)
```bash
npm i gip
```
[PNPM](https://pnpm.io/pnpm-cli#commands)
```bash
pnpm add gip
```
[DENO](https://docs.deno.com/runtime/reference/cli/add/)
```bash
deno add npm:gip
```
[BUN](https://bun.sh/docs/cli/add)
```bash
bun add gip
```
## [Module](https://nodejs.org/api/esm.html#modules-ecmascript-modules) usage
```js
import gip from "gip";
try {
const ip = await gip();
console.log(ip);
} catch (error) {
console.log(`Can't get your IP. Reason: ${error}`);
}
```
Usage with **options**
```js
import gip from "gip";
const options = {
services: ["ipv4.icanhazip.com", "ifconfig.me/ip"],
ensure: 10,
verbose: true,
};
try {
const ip = await gip(options);
console.log(ip);
} catch (error) {
console.log(`Can't get your IP. Reason: ${error}`);
}
```
## [CLI](https://en.wikipedia.org/wiki/Command-line_interface) installation
[NPM](https://docs.npmjs.com/downloading-and-installing-packages-globally)
```bash
npm i -g gip
```
[PNPM](https://pnpm.io/cli/add#--global--g)
```bash
pnpm add -g gip
```
[DENO](https://docs.deno.com/runtime/reference/cli/install/#global-installation)
```bash
deno i -g npm:gip
```
[BUN](https://bun.sh/docs/cli/install#global-packages)
```bash
bun i -g gip
```
## [CLI](https://en.wikipedia.org/wiki/Command-line_interface) usage
```bash
gip
# 133.74.20.69
```
Setting ensure option
```bash
gip --ensure 10
# 133.74.20.69
```
Passing custom services
```bash
gip --services "https://ipv4.icanhazip.com/" "https://ifconfig.me/ip"
# 133.74.20.69
```
## [CLI](https://en.wikipedia.org/wiki/Command-line_interface) usage without installation
[NPM]()
```bash
npx gip
```
[PNPM](https://pnpm.io/pnpm-cli#commands)
```bash
pnpm dlx gip
```
[DENO](https://docs.deno.com/runtime/reference/cli/run/)
```bash
deno run --allow-net npm:gip
```
[BUN](https://bun.sh/docs/cli/bunx)
```bash
bunx gip
```
## Additional info
- Passing your own services will not prioritize them. You will get answer from the fastest services anyway.
- If you pass service without specified [protocol](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol),
[HTTPS](https://en.wikipedia.org/wiki/HTTPS) will be used.
- List of built-in services is located in file [services.mjs](https://github.com/Avaray/gip/blob/main/services.mjs). If you know any
reliable services, feel free to contribute.