shell脚本中获取内网IP

前端之家收集整理的这篇文章主要介绍了shell脚本中获取内网IP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

内网IP一般为eth1网口,可以使用下面两种方法获取
方法

local_ip=`ifconfig eth1|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`

方法

local_ip=`ifconfig | perl -lane 'BEGIN{$is_eth1=0;}if($F[0]=~/^eth1$/){$is_eth1=1};if($_=~/inet addr:([\w\.]*)/ && $is_eth1==1){print $1;$is_eth1=0;}'`
原文链接:https://www.f2er.com/bash/392919.html

猜你在找的Bash相关文章