解析ifconfig来获取使用bash只有我的IP地址 [英] Parse ifconfig to get only my IP address using Bash
本文介绍了解析ifconfig来获取使用bash只有我的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编辑的.bashrc文件,有一个名为MYIP运行简单的功能。正如你可能已经猜到,功能MYIP只打印我的内部IP我的机器的地址。
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.
的据我得到了工作,这是脚本:
The far as I got working, this is the script:
ifconfig en1 | awk '{ print $2}' | sort
这有我这样的输出:
Which got my this output:
10.0.0.12
options=1<PERFORMNUD>
flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST>
fe80::daa2:5eff:fe96:ba2f%en1
d8:a2:5e:96:ba:2f
autoselect
active
我工作在Mac&NBSP; OS&NBSP; X
I'm working on Mac OS X.
我怎样才能得到这个工作?
How can I get this done?
推荐答案
好了,挣扎了几个小时之后,我终于得到了它的权利:
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}"
这是我缺少的最后一部分只是用grep IP地址的方式从我的名单。
That last part I had missing is just grep a pattern of IP addresses from my list.
这篇关于解析ifconfig来获取使用bash只有我的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文