#!/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
shell脚本获得本机ip地址
原创
©著作权归作者所有:来自51CTO博客作者四号公园的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
获取IP地址
端点(API接口)访问获取IP地址!
IP Java SpringBoot\ -
shell 获取本机IP地址
shell 获取本机IP地址
shell Linux