Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -euo pipefail
- _ip_notfound() {
- clear
- sleep 1
- echo "Erro, IP não encontrado."
- exit 1
- }
- _show_dev() {
- ip address show dev eth0
- }
- _address_condition() {
- _show_dev > /dev/null 2>&1
- }
- _ipv4() {
- if _address_condition; then
- _show_dev |
- grep -E '\w{3}[.]' |
- awk '{print $2}'
- else
- _ip_notfound
- fi
- }
- _ipv6() {
- if _address_condition; then
- _show_dev |
- grep -E 'inet6\s[0-9a-fA-F]{4}[:]' |
- awk '{print $2}'
- else
- _ip_notfound
- fi
- }
- case $1 in
- 4) _ipv4;;
- 6) _ipv6;;
- *) clear; echo "Não existe essa versão de IP, digite 4 ou 6"
- esac
Advertisement
Advertisement