この簡単なチュートリアルでは、Linuxのコマンドラインからジオロケーションを取得する方法について説明します。これは、VPSまたはリモートサーバーの場所を知りたい場合に役立ちます。 Linuxユーザーの仲間RafaelRinaldi "whereami"という便利なツールを作成しました freegeoip.netを使用してジオロケーション情報を確認するには コマンドラインから。一部のホスティングプロバイダーは、セキュリティ上の理由から、サーバーの正確な場所を隠したり、偽造したりしている可能性があることに注意してください。このような場合、このツールは役に立ちません。
それでは、whereamiユーティリティを使用してコマンドラインからLinuxシステムのジオロケーションを調べ始めましょう。
whereamiをインストールする
'whereami'ツールのインストールは非常に簡単で簡単です。 npmをインストールする必要があります 、最初にJavaScriptパッケージマネージャー。
RHEL、CentOS、FedoraなどのRPMベースのシステムにnpmをインストールするには、次のコマンドを実行します。
sudo yum install epel-release
sudo yum install npm
または、
sudo dnf install epel-release
sudo dnf install npm
Debian、Ubuntu、Linux Mintで、以下を実行します:
sudo apt-get install npm
Arch Linuxとその派生物について:
sudo pacman -S npm
SUSE / openSUSEの場合:
sudo zypper install npm
npmをインストールしたら、次のコマンドを実行して「whereami」ツールをインストールします。
npm install -g @rafaelrinaldi/whereami
以下のような出力が得られます。
/usr/bin/whereami -> /usr/lib/node_modules/@rafaelrinaldi/whereami/bin/whereami /usr/lib └─┬ @rafaelrinaldi/[email protected] ├─┬ [email protected] │ ├─┬ [email protected] │ │ └── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ └─┬ [email protected] │ └── [email protected] ├─┬ [email protected] │ └─┬ [email protected] │ ├── [email protected] │ └─┬ [email protected] │ └─┬ [email protected] │ ├── [email protected] │ └── [email protected] ├── [email protected] ├─┬ [email protected] │ └── [email protected] └── [email protected]
Linuxのコマンドラインからジオロケーションを取得する
さあ、プレイタイムです。現在地を知るには、次のコマンドを実行するだけです:
whereami
サンプル出力は次のようになります:
11.1,77.35
上記の出力にあるように、現在地の緯度(11.1)と経度(77.35)が表示されます。
わかりません。人間が読める形式にすることはできますか?もちろん、できます! -f humanを追加します 以下のようにwhereamiコマンドで切り替えます。
whereami --f human
これが私の出力です:
Tiruppur, Tamil Nadu, India
これが正確な結果であるとは言えませんが、実際の場所に非常に近いものでした。
詳細が必要ですが、それもありますか?はい!次のコマンドを使用して、パブリックIPアドレス、国コード、郵便番号、メトロコードのタイムゾーンなどを含む生の結果を表示します。
whereami -r
出力例:
{"ip":"122.178.36.244","country_code":"IN","country_name":"India","region_code":"TN","region_name":"Tamil Nadu","city":"Tiruppur","zip_code":"641603","time_zone":"Asia/Kolkata","latitude":11.1,"longitude":77.35,"metro_code":0}
whereamiコマンドの詳細については、次を実行してください:
whereami -help
出力例:
Usage: whereami [OPTIONS] Get your geolocation information using freegeoip.net from the CLI Example: $ whereami -23.4733,-46.6658 $ whereami --f human San Francisco, CA, United States Options: -v --version Display current software version -h --help Display help and usage details -f --format Output format (either human, json or sexagesimal) -r --raw Output raw data from freegeoip.net
ジオロケーションを見つけるための他のツールや方法があるかもしれないと私はかなり確信しています。他の方法を知っていますか?下のコメント欄で教えてください。
ダウンロード -無料ガイド:「初心者向けのバッシュガイド」これがお役に立てば幸いです。