欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

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

程序员文章站 2023-12-30 21:56:04
#/usr/bin/env bash # name: get_network_info.sh # author: purple_grape # this...

#/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

上一篇:

下一篇: