Sheldon Xu

Shell script: 获取适配器/IP/子网掩码/网关地址的脚本

#/bin/bash

adapter=$(ifconfig | grep -m1 'encap:Ethernet' | cut -d' ' -f1)
echo "Adapter: $adapter"

ip=$(ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
echo "IP: $ip"

mask=$(ifconfig | grep 'Mask:'| grep -v '127.0.0.1' | cut -d: -f4 | awk '{ print $1}')
echo "Mask: $mask"

gateway=$(netstat -r | grep 'default' | awk '{ print $2}')
echo "Gateway: $gateway"

posted on 2012-05-14 15:55  Sheldon Xu  阅读(2097)  评论(0编辑  收藏  举报

导航