Shell腳本獲取本地網(wǎng)卡IP、mac地址、子網(wǎng)掩碼、dns IP、外網(wǎng)IP
更新時(shí)間:2014年10月23日 10:36:45 投稿:junjie
這篇文章主要介紹了Shell腳本獲取本地網(wǎng)卡IP、mac地址、子網(wǎng)掩碼、dns IP、外網(wǎng)IP,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下
#/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
您可能感興趣的文章:
- C++實(shí)現(xiàn)獲取IP、子網(wǎng)掩碼、網(wǎng)關(guān)、DNS等本機(jī)網(wǎng)絡(luò)參數(shù)的方法
- Python實(shí)現(xiàn)根據(jù)IP地址和子網(wǎng)掩碼算出網(wǎng)段的方法
- C#設(shè)置本地網(wǎng)絡(luò)如DNS、網(wǎng)關(guān)、子網(wǎng)掩碼、IP等等
- JS 根據(jù)子網(wǎng)掩碼,網(wǎng)關(guān)計(jì)算出所有IP地址范圍示例
- js針對(duì)ip地址、子網(wǎng)掩碼、網(wǎng)關(guān)的邏輯性判斷
- 網(wǎng)絡(luò)編程基礎(chǔ)(局域網(wǎng)、ip、子網(wǎng)掩碼、網(wǎng)關(guān)、DNS)概念理解
相關(guān)文章
Shell腳本break和continue命令簡(jiǎn)明教程
這篇文章主要介紹了Shell腳本break和continue命令簡(jiǎn)明教程,break和continue命令用來在未達(dá)到循環(huán)結(jié)束條件時(shí)強(qiáng)制跳出循環(huán),需要的朋友可以參考下2014-07-07
shell腳本打印日期時(shí)間的實(shí)現(xiàn)示例
在shell 中,可以使用 `date` 命令打印系統(tǒng)時(shí)間,本文主要介紹了shell腳本打印日期時(shí)間的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09
awk中NR和FNR的區(qū)別小結(jié)和實(shí)例演示
這篇文章主要介紹了awk中NR和FNR的區(qū)別小結(jié)和實(shí)例演示,著重介紹NR和FNR不同的地方,需要的朋友可以參考下2014-07-07
shell學(xué)習(xí)教程獲取命令行參數(shù)示例
這篇文章主要介紹了shell學(xué)習(xí)中的基礎(chǔ)知識(shí)的獲取命令行參數(shù)示例,需要的朋友可以參考下2014-03-03
Shell腳本實(shí)現(xiàn)簡(jiǎn)單分割字符串
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)簡(jiǎn)單分割字符串,本文講解使用CUT命令實(shí)現(xiàn)以逗號(hào)、分號(hào)或其它分隔符來切割字符串,需要的朋友可以參考下2015-02-02

