获取网卡信息
2016-08-30 20:29
281 查看
获取网卡信息
获取网卡名:
获取eth0的ip地址:
红帽7上的方法
不同的系统ifconfig得到的信息不同修改grep的内容来准确获取
获取指定IP的网卡名:
编写一个getinterface.sh脚本,可以接受选项{-i,-I,-a},完成以下功能:
1、使用以下形式:getinterface.sh [-i interface | -I IP | -a]
2、当用户使用-i时,显示其指定网卡的IP地址
3、当用户使用-I时,显示其指定IP地址的网络接口
4、当用户使用-a时,显示其所有的网络接口和其IP地址(除LO接口外)
获取网卡名:
#ifconfig | grep -o "^[^[:space:]]\{1,\}”
获取eth0的ip地址:
#ifconfig eth0 | grep -o "inet addr:[0-9\.]\{1,\}" | cut -d: -f2
红帽7上的方法
#ifconfig eth0 | grep -o "inet [0-9\.]\{1,\}" | cut -d' ' -f2
不同的系统ifconfig得到的信息不同修改grep的内容来准确获取
获取指定IP的网卡名:
#ifconfig | grep -B 1 "192.168.0.99" | grep -o "^[^[:space:]]\{1,\}"
编写一个getinterface.sh脚本,可以接受选项{-i,-I,-a},完成以下功能:
1、使用以下形式:getinterface.sh [-i interface | -I IP | -a]
2、当用户使用-i时,显示其指定网卡的IP地址
3、当用户使用-I时,显示其指定IP地址的网络接口
4、当用户使用-a时,显示其所有的网络接口和其IP地址(除LO接口外)
#!/bin/bash # #Name:getinterface.sh #Description:Get ethernet information #Author:chen #Version:0.0.1 #date time:2016-08-29 22:01:53 #Usage:getinterface.sh SHOWIP (){ if ! ifconfig |grep -o "^[^[:space:]]\{1,\}"|grep $1 &> /dev/null;then return 13 fi echo -n "$1:" ifconfig $1 | grep -o "inet [0-9\.]\{1,\}" | cut -d' ' -f2 } SHOWETHER(){ if ! ifconfig | grep -o "inet [0-9\.]\{1,\}" | cut -d' ' -f2 | grep ^"$1"$ &> /dev/null;then return 14 fi echo -n "$1:" ifconfig | grep -B 1 "$1" | grep -o "^[^[:space:]]\{1,\}"|cut -d: -f1-2 } SHOWALL () { ifconfig | grep -o "^[^[:space:]]\{1,\}"|grep -o "[a-z,A-Z,0-9].*[^:]" > ether.txt while read LINE;do if [ $LINE != "lo" ];then SHOWIP $LINE fi done < ether.txt rm -f ether.txt } USAGE () { echo "getinterface.sh <-i interface | -I IP | -a >" } while getopts ":i:I:a" SWICH;do case $SWICH in i) SHOWIP $OPTARG [ $? -eq 13 ] && echo "Wrong ethercard" ;; I) SHOWETHER $OPTARG [ $? -eq 14 ] && echo "Wrong IP" ;; a) SHOWALL ;; *) USAGE ;; esac done
相关文章推荐
- VC学习资料收集(25):获取硬盘ID信息及网卡MAC地址的代码
- 如何通过VB.net获取网卡信息
- ndis hook开发日志(2)-获取网卡信息 - Kevins的天空 http://rootsec.tk - CSDNBlog
- C#获取硬件信息(CPU序列号,网卡地址...)
- 计算机网卡获取信息获取、启用、停止 上篇中存在的问题
- 网卡MAC地址相关信息大全-2 获取网卡MAC的3个方法
- javascript利用wmi获取客户端网卡信息
- C#获取CPU网卡等硬件信息
- 计算机网卡获取信息获取、启用、停止
- _NetworkAdapterInfo 获取系统网卡详细信息
- Java 程序获取系统硬件信息之网卡MAC地址
- 获取网卡信息
- 网卡MAC地址相关信息大全-4 获取远程网卡MAC地址
- 获取网卡、硬盘、CPU硬件信息
- Linux下获取网卡信息
- ndis hook开发日志(2)-获取网卡信息
- C# 获取机器CPU信息,硬盘信息,网卡信息
- 获取硬盘ID信息及网卡MAC地址的代码
- VS6.0下使用 IP Help API(Iphlpapi.dll)系列函数之GetAdaptersAddresses(GetAdaptersInfo) 获取网卡信息简述
- 获取网卡相关信息