#!/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
时间: 2024-10-19 19:36:26