LoginSignup
28
21

More than 5 years have passed since last update.

接続もとのIPアドレスを表示するスクリプト

Posted at

SSHとかでサーバーに接続している場合に、接続元(自分のPCとか)のIPアドレスをシェルが知りたいという場合に、そのIPアドレスを抽出するスクリプト。

$ who am i | cut -d '(' -f 2 | sed -e 's/)//g'
192.168.0.1

SSH接続した場合は環境変数のSSH_CONNECTIONでIP取れるんですが、su -しちゃうとクリアされちゃうのでwho am iから取得しています。もっと簡単に出せるコマンドとかないのかな。。。

28
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
21