Shell脚本获取本地网卡IP、mac地址、子网掩码、dns IP、外网IP
2019/7/10 21:49:41
本文主要是介绍Shell脚本获取本地网卡IP、mac地址、子网掩码、dns IP、外网IP,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#/usr/bin/env bash # Name: get_network_info.sh # Author: Purple_Grape # This is a script to gather network information of your Linux system. # Test under Ubuntu 10.04 only. #---------------------------- NIC=eth0 MAC=`LANG=C ifconfig $NIC | awk '/HWaddr/{ print $5 }' ` IP=`LANG=C ifconfig $NIC | awk '/inet addr:/{ print $2 }' | awk -F: '{print $2 }'` MASK=`LANG=C ifconfig $NIC | awk -F: '/Mask/{print $4}'` ext_ip=`curl ifconfig.me` if [ -f /etc/resolv.conf ]; then dns=`awk '/^nameserver/{print $2}' /etc/resolv.conf ` fi #---------------------------- echo "Your network information is as below:" echo $MAC echo $IP echo $dns echo $ext_ip
这篇关于Shell脚本获取本地网卡IP、mac地址、子网掩码、dns IP、外网IP的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!