shell脚本获得本机ip地址
#!/bin/bash #author: #date:2015-6-13 #filename:ip.sh ############################# ifconfig_cmd=`which ifconfig` $ifconfig_cmd > ifconfig.me ################################### function obtain_ip_information(){ if grep -q ‘bond‘ ifconfig.me then bond_name=`cat ifconfig.me | grep bond | grep -v grep | awk ‘{print $1}‘` current_ip=`"${ifconfig_cmd}" "${bond_name}" | grep Bcast | awk ‘{print $2}‘ | awk -F ":" ‘{print $2}‘` current_netmask="255.255.255.0" current_gateway=`echo ${current_ip} | cut -f 1-3 -d "." | sed ‘s/$/\.254/g‘` echo ${current_ip} echo ${current_netmask} echo ${current_gateway} elif grep -q ‘eth‘ ifconfig.me then current_ip=`${ifconfig_cmd} eth0 | grep Bcast | awk ‘{print $2}‘ | awk -F ":" ‘{print $2}‘` current_netmask="255.255.255.0" current_gateway=`echo ${current_ip} | cut -f 1-3 -d "." | sed ‘s/$/\.254/g‘` echo ${current_ip} echo ${current_netmask} echo ${current_gateway} else echo ‘网卡非bond,非eth0,请手工检查‘ exit 3 fi } obtain_ip_information
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。