Parse ifconfig to get only my IP address using Bash

后端 未结 20 1255
甜味超标
甜味超标 2020-11-30 05:04

I want to edit the bashrc file to have a simple function called \"myip\" to run. As you might guess, the function myip prints only my internal IP address of my machine.

20条回答
  •  旧时难觅i
    2020-11-30 05:37

    Well, after hours of struggling I finally got it right:

    ifconfig en1 | awk '{ print $2}' | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"
    

    That last part I had missing is just grep a pattern of IP addresses from my list.

提交回复
热议问题