BASH 12
Rede.sh Guest on 21st November 2020 05:36:31 PM
  1. #!/bin/sh
  2. # Retorna informações sobre as placas de rede
  3. #
  4.  
  5. for IFACE in `ifconfig -a |grep ^"[ea]th" |cut -d " " -f 1`; do
  6. #echo 1
  7.   TMP=`ifconfig $IFACE |head -n 1`      #Interface e MAC
  8. #  L_IFACE=`echo $TMP |cut -d ":" -f 1`  #Linha da Inteface
  9.   MAC=`    echo $TMP |cut -d " " -f 5`  #Enderecao MAC
  10. #echo 11
  11.   if ifconfig $IFACE |grep -qs UP; then #Estado
  12.     STATE="UP"
  13.   else
  14.     STATE="DOWN"
  15.   fi
  16.   TMP=`ifconfig $IFACE |grep Bcast` #Ip, Broadcast e mascara
  17. #echo 12
  18.   if [ "$STATE" = "UP" ]; then            #Endereço IP
  19.     ADDR=` echo $TMP |cut -d ":" -f 2 |cut -d " " -f 1`
  20.     BCAST=`echo $TMP |cut -d ":" -f 3 |cut -d " " -f 1`
  21.     MASK=` echo $TMP |cut -d ":" -f 4 |cut -d " " -f 1`
  22.   else
  23.     ADDR=""
  24.     BCAST=""
  25.     MASK=""
  26.   fi  
  27.  
  28.   TMP=`ifconfig $IFACE |grep Interr` #IRQ e Addr
  29.   IRQ=`echo $TMP |cut -d ":" -f 2 |cut -d " " -f 1`
  30.   BADDR=`echo $TMP |cut -d ":" -f 3`
  31.  
  32.   #Acha o PCI-ID da Interface
  33.   for I in `grep -n "Ethernet" /proc/pci |cut -d ":" -f 1`; do
  34.     TMP=`cat /proc/pci |head -n $((I+1)) |tail -n 1 |cut -d " " -f 8 |cut -d "." -f 1`
  35.     if [ $TMP = $IRQ ]; then
  36.       DEVICE=`cat /proc/pci |head -n $I |tail -n 1|cut -d ":" -f 2`
  37.     fi
  38.   done
  39.  
  40.   MODULO=`./ethtool -i $IFACE |grep driver |cut -d: -f2`
  41.  
  42.   echo "---------------------------------------------------------------------"
  43.   echo "Interface.: "$IFACE
  44.   echo "Estado....: "$STATE
  45.   echo "MAC.......: "$MAC
  46.   echo "Address...: "$ADDR
  47.   echo "Broadcast.: "$BCAST
  48.   echo "Mask......: "$MASK
  49.   echo "IRQ.......: "$IRQ" / Base address: "$BADDR
  50.   echo "Device....:"$DEVICE
  51.   echo "Modulo....:"$MODULO
  52.   echo "---------------------------------------------------------------------"
  53. done

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.