diff --git a/scripts/getIp b/scripts/getIp index ffe9ac9..85af249 100755 --- a/scripts/getIp +++ b/scripts/getIp @@ -1,7 +1,7 @@ #!/bin/bash -version=1.6.0 -date="03/09/2017" +version=1.7.0 +date="04/09/2017" projet="simpledeb" contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/" script="getIp" @@ -18,7 +18,6 @@ f__affichage(){ # v27/08/2017 définition couleurs BLUE="$(printf "\033[0;34m")" # info RED="$(printf "\033[0;31m")" # alerte COLOR="$(printf "\033[0m")" # standard -# echo } # affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade @@ -165,7 +164,7 @@ cat << 'EOF' -h, --help : affichage aide -4, --ip4 : affiche ipv4 public -6, --ip6 : affiche ipv6 public - '', --local : affiche ip / passerelle privées + '', --local : affiche adresses mac / ip privées / passerelle -i, --install : installation du script dans le système -r, --remove : suppression du script dans le système @@ -175,16 +174,23 @@ EOF echo "$COLOR" } - # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type -figet_ip() { # v03/09/2017 + # assigne $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type + # $ifnames, $ifnames_type, $mac_address, mac_address_type +figet_ip() { # v04/09/2017 [ -z "$(which ip)" ] && return 1 - ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print " ",$4,"(",$2,")"}')" + ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print " ",$4,"(",$2,")"}')" ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)" - gateway="$(LC_ALL=C ip -4 route | awk '/default via/ {print " ",$3,"(",$5,")"}'; LC_ALL=C ip -6 route | awk '/default via/ {print " ",$3,"(",$5,")"}')" + gateway="$(LC_ALL=C ip -4 route | awk '/default via/ {print " ",$3,"(",$5,")"}'; LC_ALL=C ip -6 route | awk '/default via/ {print " ",$3,"(",$5,")"}')" gateway_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $gateway)" - gateway_one="$(head -n 1 <<< $gateway | awk '{print " ",$1}')" - ifname="$(ip -4 route | awk '/proto kernel/ {print " ",$3}')" - ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)" + gateway_one="$(head -n 1 <<< $gateway | awk '{print " ",$1}')" + for ifn in $(ls /sys/class/net/) ; do + [ "$ifn" != "lo" ] && ifnames+=" $ifn"$'\n' # $'\n' -> newline ou $'\x0a' ou $'\012' + [ "$ifn" != "lo" ] && mac_address+=" $ifn: $(cat /sys/class/net/$ifn/address)"$'\n' + done + ifnames="$(sed '/^$/d' <<< $ifnames)" # suppression \n final + ifnames_type+="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ifnames)" + mac_address="$(sed '/^$/d' <<< $mac_address)" # suppression \n final + mac_address_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $mac_address)" } # $1=4|6, assigne $ip_public @@ -410,8 +416,8 @@ testuser(){ } # initialisation -PATH='/usr/sbin:/usr/bin:/sbin:/bin' ; IFS=' '; TERM=xterm -export PATH TERM +PATH='/usr/sbin:/usr/bin:/sbin:/bin'; TERM=xterm; IFS=$' \t\n' +export PATH TERM IFS f__affichage fileLogs="/var/log/sdeb_$script.log" fileDev="/opt/bin/fileDev" @@ -438,6 +444,7 @@ for i in "$options"; do figet_ip || f__error "iproute2 doit être installé" "il remplace net-tools qui n'est plus développé" echo -e "\n ip locale(s):\n$BLUE$ip_local_type\n$COLOR" echo -e " passerelle(s):\n$BLUE$gateway_type\n$COLOR" + echo -e " mac_address:\n$BLUE$mac_address_type\n$COLOR" ;; # affiche ip locales -i | --install ) testuser diff --git a/scripts/getIp_changelog.md b/scripts/getIp_changelog.md index 098f46e..8213adc 100644 --- a/scripts/getIp_changelog.md +++ b/scripts/getIp_changelog.md @@ -1,6 +1,14 @@ # changelog getIp +## 1.7.0 04/09/2017 + +* nouveau IFS +* révision figet_ip: + * ifnames, toutes les interfaces et pas seulement les connectées + * mac address des interfaces +* nouveau: affichage adresses mac + ## 1.6.0 03/09/2017 * mieux: test connectivité avant recherche ip public pour éviter timeout, figet_ip_public