Shell脚本获取本地网卡IP、mac地址、子网掩码、dns IP、外网IP

发布时间:2022-04-19 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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全部内容,希望文章能够帮你解决Shell脚本获取本地网卡IP、mac地址、子网掩码、dns IP、外网IP所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。