Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How can I get the primary IP address of the local machine on Linux and OS X? - bug-code.com Q&A

How can I get the primary IP address of the local machine on Linux and OS X?

0 like 0 dislike
44 views
asked by (4.3k points) | 44 views

1 Answer

0 like 0 dislike

You can use grep to filter IP address from ifconfig

ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'

Also you can do it sed

ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'

Put wlan0, eth0, etc if you need certain interfaces:

ifconfig wlan0 | ...

answered by (8.5k points)
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.7k users

24,788 questions
46,220 answers
0 comments
12,685 users