亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 求助如何獲取隨機(jī)網(wǎng)卡名稱; [打印本頁]

作者: skygts    時(shí)間: 2015-05-26 10:48
標(biāo)題: 求助如何獲取隨機(jī)網(wǎng)卡名稱;
本帖最后由 skygts 于 2015-05-26 10:49 編輯

[root@cloud ppp]# ifconfig
eth4      Link encap:Ethernet  HWaddr 00:15:5D:5B:54:B7  
          inet6 addr: fe80::215:5dff:fe5b:54b7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1203335 errors:0 dropped:0 overruns:0 frame:0
          TX packets:984 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:155312667 (148.1 MiB)  TX bytes:334944 (327.0 KiB)

eth5      Link encap:Ethernet  HWaddr 00:15:5D:5B:54:B8  
          inet addr:192.168.9.58  Bcast:192.168.9.255  Mask:255.255.255.0
          inet6 addr: fe80::215:5dff:fe5b:54b8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:558272 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11629 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:60021556 (57.2 MiB)  TX bytes:1539407 (1.4 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:13 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1235 (1.2 KiB)  TX bytes:1235 (1.2 KiB)
         
請(qǐng)問一下系統(tǒng)里eth是隨機(jī)的有可能是eth4、eth5 也有可能是 eth7、eth8,有一張網(wǎng)卡只有MAC地址沒有IP地址如何通過shell獲取沒有IP的網(wǎng)卡名稱,也就是獲取“eth4”這個(gè)名稱
我寫的腳本如下,請(qǐng)指教一下。
#! /bin/sh
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
for i in 0 1 2 3 4 5 6 7 8 9
do
NIC=eth"$i"
MAC=`LANG=C ifconfig $NIC 2>/dev/unll| awk '/HWaddr/{ print $5 }' `
IP=`LANG=C ifconfig $NIC 2>/dev/null | awk '/inet addr:/{ print $2 }' | awk -F: '{print $2 }'`
if [ ! -n "$IP" ] && [  -n "$MAC" ]; then
     echo "$NIC" > /root/1.txt
else
     echo "" >/dev/null
fi

done
作者: jason680    時(shí)間: 2015-05-26 11:16
回復(fù) 1# skygts

$ ifconfig | awk -F'[ :]+' '!NF{if(eth!=""&&ip=="")print eth;eth=ip4=""}/^[^ ]/{eth=$1}/inet addr:/{ip=$4}'
eth4
   
作者: Buring__    時(shí)間: 2015-05-26 11:32
回復(fù) 1# skygts
  試一下
  1. ifconfig |awk -vRS=""  '/HWaddr/&&!/inet addr:/{print $1}'
復(fù)制代碼

作者: songyc_2015    時(shí)間: 2015-05-26 11:48
本帖最后由 songyc_2015 于 2015-05-26 14:24 編輯

回復(fù) 1# skygts
  1. ifconfig | sed -nr '/^[^ ]/h;/^ /{:a;H;n;/^$/!ba;g;/inet addr/!{s# .*$##p;};}'
復(fù)制代碼

作者: skygts    時(shí)間: 2015-05-26 11:48
回復(fù) 2# jason680

非常感謝?梢垣@取了。謝謝!
作者: skygts    時(shí)間: 2015-05-26 11:49
songyc_2015 發(fā)表于 2015-05-26 11:48
回復(fù) 1# skygts


效率太高了。非常感謝。
作者: sa202017    時(shí)間: 2018-04-22 14:31
回復(fù) 4# songyc_2015

rhel7.x中,名稱后面有了一個(gè)":",怎么去掉呢?





歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2