npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

IPinfo CLI


This is the official CLI for the IPinfo.io IP address API, allowing you to:

Look up IP details in bulk or one-by-one.
Look up ASN details.
Summarize the details of up to 1000 IPs at a time.
Open a map of IP locations for any set of IPs.
Filter IPv4 & IPv6 addresses from any input.
Print out IP lists for any CIDR or IP range.
And more!

Installation


The ipinfo CLI is available for download via multiple mechanisms.

macOS


  1. ``` shell
  2. brew install ipinfo-cli
  3. ```

OR to install the latest amd64 version without automatic updates:

  1. ``` shell
  2. curl -Ls https://github.com/ipinfo/cli/releases/download/ipinfo-2.10.1/macos.sh | sh
  3. ```

Ubuntu PPA


Note: this installs our full suite of binaries and keeps them up-to-date.

  1. ``` shell
  2. sudo add-apt-repository ppa:ipinfo/ppa
  3. sudo apt update
  4. sudo apt install ipinfo
  5. ```

Debian / Ubuntu (amd64)


Note: this is a one-time installation; updates are not automatic. Use the PPA for automatic updates.

  1. ``` shell
  2. curl -Ls https://github.com/ipinfo/cli/releases/download/ipinfo-2.10.1/deb.sh | sh
  3. ```

OR

  1. ``` shell
  2. curl -LO https://github.com/ipinfo/cli/releases/download/ipinfo-2.10.1/ipinfo_2.10.1.deb
  3. sudo dpkg -i ipinfo_2.10.1.deb
  4. ```

FreeBSD


  1. ``` shell
  2. cd /usr/ports/net/ipinfo-cli && make install clean
  3. ```

Arch linux


  1. ``` shell
  2. git clone https://aur.archlinux.org/ipinfo-cli.git
  3. makepkg -si
  4. ```

Windows Powershell


Note: run powershell as administrator before executing this command.

  1. ``` shell
  2. iwr -useb https://github.com/ipinfo/cli/releases/download/ipinfo-2.10.1/windows.ps1 | iex
  3. ```

Scoop


  1. ``` shell
  2. scoop install ipinfo-cli
  3. ```

Docker


  1. ``` shell
  2. docker run --rm -it ipinfo/ipinfo:2.10.1
  3. ```

To save the CLI's config, add -v "/path_to_config:/root/.config/ipinfo". For example, the following command saves the config to the ipinfo directory in the current working directory.

  1. ``` shell
  2. docker run --rm -it -v "$PWD/ipinfo:/root/.config/ipinfo" ipinfo/ipinfo:2.10.1
  3. ```

Using go install


Make sure that $GOPATH/bin is in your $PATH, because that's where this gets installed:

  1. ``` shell
  2. go install github.com/ipinfo/cli/ipinfo@latest
  3. ```

Using curl/wget


The pre-built binaries for all platforms are available on GitHub via artifacts in releases. You need to simply download, unpack and move them to your shell's binary search path.

The following OS & arch combinations are supported (if you use one not listed on here, please open an issue):

  1. ``` sh
  2. darwin_amd64
  3. darwin_arm64
  4. dragonfly_amd64
  5. freebsd_386
  6. freebsd_amd64
  7. freebsd_arm
  8. freebsd_arm64
  9. linux_386
  10. linux_amd64
  11. linux_arm
  12. linux_arm64
  13. netbsd_386
  14. netbsd_amd64
  15. netbsd_arm
  16. netbsd_arm64
  17. openbsd_386
  18. openbsd_amd64
  19. openbsd_arm
  20. openbsd_arm64
  21. solaris_amd64
  22. windows_386
  23. windows_amd64
  24. windows_arm

  25. ```

After choosing a platform PLAT from above, run:

  1. ``` shell
  2. # for Windows, use ".zip" instead of ".tar.gz"
  3. curl -LO https://github.com/ipinfo/cli/releases/download/ipinfo-2.10.1/ipinfo_2.10.1_${PLAT}.tar.gz
  4. # OR
  5. wget https://github.com/ipinfo/cli/releases/download/ipinfo-2.10.1/ipinfo_2.10.1_${PLAT}.tar.gz

  6. tar -xvf ipinfo_2.10.1_${PLAT}.tar.gz
  7. mv ipinfo_2.10.1_${PLAT} /usr/local/bin/ipinfo
  8. ```

Using git


Installing from source requires at least the Golang version specified in go.mod. You can install the Golang toolchain from the official site.

Once the correct Golang version is installed, simply clone the repository and install the binary:

  1. ``` shell
  2. git clone https://github.com/ipinfo/cli ipinfo-cli
  3. cd ipinfo-cli
  4. go install ./ipinfo/
  5. $GOPATH/bin/ipinfo
  6. ```

You can add $GOPATH/bin to your $PATH to access ipinfo directly from anywhere.

Alternatively, you can do the following to output the binary somewhere specific:

  1. ``` shell
  2. git clone https://github.com/ipinfo/cli ipinfo-cli
  3. cd ipinfo-cli
  4. go build -o <path> ./ipinfo/
  5. ```

Replace <path> with the required location.

Additional CLIs


The ipinfo CLI has some subcommands like grepip, prips, cidr2range, cidr2ip, range2cidr, range2ip, splitcidr and randip which are also shipped as standalone binaries.

These binaries are available via all the same installation methodsas mentioned above for ipinfo, except you must change only the name to the name of the subcommand, and choose the appropriate version.

Currently these subcommands are separately shipped:

CLI Version
:--- :---
grepip 1.2.1
prips 1.0.0
cidr2range 1.2.0
cidr2ip 1.0.0
range2cidr 1.3.0
range2ip 1.0.0
randip 1.1.0
splitcidr 1.0.0

Quick Start


This will help you quickly get started with the ipinfo CLI.

Default Help Message


By default, invoking the CLI shows a help message:

  1. ``` shell
  2. ipinfo
  3. ```

ipinfo

Login


If you have a token, log in with it first. You can continue without a token, but there will be limited data output and some features (like bulk lookups) will not be available. Get your token for free at https://ipinfo.io/signup.

  1. ``` shell
  2. ipinfo init
  3. ```

My IP


You can quickly look up details of your own IP with myip :

  1. ``` shell
  2. ipinfo myip
  3. ```

ipinfo myip

Any IP


You can see the details of any IP by specifying it:

  1. ``` shell
  2. ipinfo 8.8.8.8
  3. ```

ipinfo myip

Piping


You can pipe IPs in and get their results in bulk (this requires a token):

  1. ``` shell
  2. cat ips.txt | ipinfo | less
  3. ```

cat ips.txt | ipinfo

Here's the CSV version of that:

  1. ``` shell
  2. cat ips.txt | ipinfo -c | less
  3. ```

cat ips.txt | ipinfo -c

Field Filter


In case you only needed a single field from a bunch of IPs:

  1. ``` shell
  2. cat ips.txt | ipinfo -f hostname
  3. ```

cat ips.txt | ipinfo

Bulk


The above commands implicitly run the bulk subcommand on the input. You can manually specify bulk and input IPs on the command line:

  1. ``` shell
  2. ipinfo bulk 1.1.1.0/30 8.8.8.0/30 9.9.9.0/30 | less
  3. ```

ipinfo bulk

Summarize


IP details can be summarized similar to what's provided by https://ipinfo.io/tools/summarize-ips :

  1. ``` shell
  2. cat lk-ips.txt | ipinfo summarize
  3. ```

ipinfo summarize

There are many more features available, so for full details, consult the -h or --help message for each command. For example:

  1. ``` shell
  2. ipinfo 8.8.8.8 --help
  3. ```

Auto-Completion


Auto-completion is supported for at least the following shells:

  1. ``` sh
  2. bash
  3. zsh
  4. fish

  5. ```

NOTE: it may work for other shells as well because the implementation is in Golang and is not necessarily shell-specific.

Installation


Installing auto-completions is as simple as running one command (works for bash, zsh and fish shells):

  1. ``` shell
  2. ipinfo completion install
  3. ```

If you want to customize the installation process (e.g. in case the auto-installation doesn't work as expected), you can request the actual completion script for each shell:

  1. ``` shell
  2. # get bash completion script
  3. ipinfo completion bash

  4. # get zsh completion script
  5. ipinfo completion zsh

  6. # get fish completion script
  7. ipinfo completion fish
  8. ```

Shell not listed?


If your shell is not listed here, you can open an issue.

Note that as long as the COMP_LINE environment variable is provided to the binary itself, it will output completion results. So if your shell provides a way to pass COMP_LINE on auto-completion attempts to a binary, then have your shell do that with the ipinfo binary itself (or any of our binaries).

Data


The amount of data you get back per lookup depends upon how much data you have enabled on your token via the https://ipinfo.io site.

If you have an account, see our plans and addons.

All examples in this document use a token with all data enabled.

Color Output


Disabling Color Output


All our CLIs respect either the --nocolor flag or the NO_COLOR environment variable to disable color output.

Color on Windows


To enable color support for the Windows command prompt, run the following to enable Console Virtual Terminal Sequences.

  1. ``` batchfile
  2. REG ADD HKCU\CONSOLE /f /v VirtualTerminalLevel /t REG_DWORD /d 1
  3. ```

You can disable this by running the following:

  1. ``` batchfile
  2. REG DELETE HKCU\CONSOLE /f /v VirtualTerminalLevel
  3. ```

Other IPinfo Tools


There are official IPinfo client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third party libraries and integrations available for our API.

See https://ipinfo.io/developers/libraries for more details.

About IPinfo


Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.
Last Updated: 2023-08-14 08:36:17