用shell脚本输出网络接口及IP地址

回复 收藏
用shell脚本实现输出网络接口和IP地址,输出形式为:eth0 192.168.0.106
                                                                        lo 127.0.0.1
  1. #! /bin/bash
  2. # The prupose of the shell script is to obtian the ibterface IP address
  3. ifconfig |egrep 'eth0|lo|inet addr' |awk -F ' ' '{print $1,$2}' |grep -n '.*' |grep -i 'inet' |cut -d':' -f1,3 >2.txt
  4. ifconfig |egrep 'eth0|lo|inet addr' |awk -F ' ' '{print $1,$2}'|grep -n '.*'|grep -i 'link' |cut -d' ' -f1 >1.txt
  5. cat 1.txt 2.txt |sort|cut -d: -f2 |grep -A1 'eth0' >11.txt
  6. cat 1.txt 2.txt |sort|cut -d: -f2 |grep -A1 'lo' >22.txt
  7. cat 11.txt |xargs;cat 22.txt |xargs
2014-03-20 11:12 举报
已邀请:
0

xyl5869

赞同来自:

相见很晚啊!谢谢!

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: