Vous connaissez très certainement cette méthode en bash pour afficher votre IP avec l’outil cut :
ifconfig $IF | grep "inet ad" | cut -d':' -f2 | cut -d' ' -f1 |
ifconfig $IF | grep "inet ad" | cut -d':' -f2 | cut -d' ' -f1
Voici la même chose pour afficher toutes les IPv6 d’une interface $IF (avec le masque)
ifconfig $IF | grep inet6 | cut -d':' -f2- | cut -d' ' -f2 |
ifconfig $IF | grep inet6 | cut -d':' -f2- | cut -d' ' -f2
Même chose sans le masque de préfixe :
ifconfig $IF | grep inet6 | cut -d':' -f2- | cut -d' ' -f2 | cut -d'/' -f1 |
ifconfig $IF | grep inet6 | cut -d':' -f2- | cut -d' ' -f2 | cut -d'/' -f1
Petite édition, voici la même chose mais avec la commande ip (iproute) de linux, testé sur des debian mais pas encore ailleurs 🙂 :
Pour obtenir l’adresse lien-local link-local :
ip -6 addr show scope link dev $IF | grep inet6 | cut -d' ' -f6 |
ip -6 addr show scope link dev $IF | grep inet6 | cut -d' ' -f6
Sans masque :
ip -6 addr show scope link dev $IF | grep inet6 | cut -d' ' -f6 | cut -d'/' -f1 |
ip -6 addr show scope link dev $IF | grep inet6 | cut -d' ' -f6 | cut -d'/' -f1
Pour la ou les adresse(s) globale(s) global unicast :
ip -6 addr show scope global dev $IF | grep inet6 | cut -d' ' -f6 |
ip -6 addr show scope global dev $IF | grep inet6 | cut -d' ' -f6
Sans masque :
ip -6 addr show scope global dev $IF | grep inet6 | cut -d' ' -f6 | cut -d'/' -f1 |
ip -6 addr show scope global dev $IF | grep inet6 | cut -d' ' -f6 | cut -d'/' -f1