0
1

Macのifconfig/ipconfigコマンドでプライベートIPアドレスのみ表示する

Last updated at Posted at 2024-01-14

MacでプライベートIPアドレスを確認したい場合、以下のコマンドを実行することで確認可能です。

$ ifconfig en0
en0: flags=xxx
	options=xxx
	ether xxx
	inet6 xxx
	inet xxx.xxx.xxx.xxx netmask xxx broadcast xxx // inetの部分
	nd6 options=xxx
	media: xxx
	status: xxx

en0は使用しているネットワークインターフェース名でen0はWi-Fiが使用しています。

$ networksetup -listallhardwareports
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: xxxxx

ここでinetのIPアドレスの部分のみ表示したい場合、以下のコマンドを実行します。

ifconfigの場合

$ ifconfig en0 | grep 'inet ' | awk '{print $2}'
xxx.xxx.xxx.xxx

ipconfigの場合

$ ipconfig getifaddr en0
xxx.xxx.xxx.xxx

「Mac IPアドレス 確認コマンド」でGoogle検索すると、「Windowsの場合はipconfig、Macの場合はifconfigを使う」みたいな感じでヒットする記事が多かったが、ipconfigでもいけるみたいです。

参考

0
1
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
0
1