La eficiencia es lo que persigues, la eficiencia es lo que
persigues—— Líder anterior propietario
No es tanto un blog, es mejor decir que este es un shell script que tiene 6 meses de retraso.
En agosto de 2021, el líder me pidió que escribiera un script para obtener la dirección IP de la máquina física con precisión
. Hoy, es finalmente realizado, conmemorar
Primero mira el efecto
Echemos un vistazo al contenido del script.
Código abierto con todos, comparte un ha, bienvenido con un clic de tres conexiones (como , seguir , favorito ) ¡yo!
#!/bin/bash
# Author: IT-coding
# Date: 2022-02-23 21:22
# blog: https://qchenz.blog.csdn.net/
pkgs(){
yum install iproute iproute2 net-tools hostname -y
}
netAdapter(){
hw=`ip a|grep -v "1:"|grep -v "inet6"|grep "2:"|awk '{print $2}'`
hw2=${hw%:*}
}
getIpWay1(){
echo " == get local IP Way1 == "
net1=`ip a|grep "${hw2}"|grep "inet"|awk '{print $2}'`
echo ${net1%/*}
}
getIpWay2(){
echo " == get local IP Way2 == "
net2=`ifconfig ${
hw2}|grep "inet"|grep -v "inet6"|awk '{print $2}'`
echo ${net2}
}
getIpWay3(){
echo " == get local IP Way3 == "
net3=`hostname -I|awk '{print $1}'`
echo ${net3}
}
main(){
echo "=== LET'S BEGIN GETTING LOCAL IP ADDRESS... ==="
pkgs
netAdapter
getIpWay1
getIpWay2
getIpWay3
echo "=== GOT LOCAL IP ADDRESS FINISHED! ==="
}
main
Amigos, ¿han perdido sus estudios?
¡Hasta la próxima, adiós!