如何获得格式化为“接口:IP地址”的输出来自Mac上的ifconfig [英] How to get an output formatted as "Interface: IP Address" from ifconfig on Mac
本文介绍了如何获得格式化为“接口:IP地址”的输出来自Mac上的ifconfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
en0:10.52.30.105
en1我想从ifconfig中获得以下格式化输出: :10.52.164.63
我至少能弄清楚如何获得IP地址(除去本地主机),但是这对我的需求是不够的:
ifconfig | grep -E'inet。[0-9]'| grep -v'127.0.0.1'| awk'{print $ 2}'
谢谢!
>解决方案
这适用于FreeBSD,它是苹果的核心: - )
#!/ bin / sh
for $ in($ ifconfig -l);在
(lo0)
;中做
的情况下的$ i;
(*)
set - $(ifconfig $ i | grepinet [1-9])
if $#-gt 1;然后
echo $ i:$ 2
fi
esac
完成
I am trying to get the following formatted output out of ifconfig:
en0: 10.52.30.105
en1: 10.52.164.63
I've been able to at least figure out how to get just the IP addresses (weeding out localhost) with the following command, but it's not sufficient for my requirements:
ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'
Thanks!
解决方案
This works on FreeBSD, which is at the heart of an apple :-)
#!/bin/sh
for i in $(ifconfig -l); do
case $i in
(lo0)
;;
(*)
set -- $(ifconfig $i | grep "inet [1-9]")
if test $# -gt 1; then
echo $i: $2
fi
esac
done
这篇关于如何获得格式化为“接口:IP地址”的输出来自Mac上的ifconfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文