J'ai un petit concours bash.
Récupérer à l'aide d'un script de manière la plus élégante, la plus fiable, et la plus portable les paramètre de configuration de la pile TCP/IP Linux.
Je me lance, mais c'est pas très joli:
IP=`ifconfig | egrep 'inet add?r:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
MASK=`ifconfig | egrep 'inet add?r:'| grep "$IP" | cut -d: -f4`
GATEWAY=`route -n | egrep "^0.0.0.0 +[[:digit:].]+ +0.0.0.0" | awk '{print $2}'`
DNS=`grep nameserver /etc/resolv.conf | head -1 | awk '{print $2}'`
Merci pour votre aide.
# Cleaner
Posté par Xavier . Évalué à 1.
IP= $(ifconfig | awk -F ":" '/inet addr/ {print $2 }' | cut -d " " -f1);
Pour te mettre sur la voie.
@+ et bonne chance
[^] # Re: Cleaner
Posté par snt . Évalué à 3.
ifconfig | awk -F ":" '/inet addr/ {print substr($2,0, index($2," ")) }'
[^] # Re: Cleaner
Posté par snt . Évalué à 2.
ifconfig | awk -F ":" '/inet addr/ {print substr($2,0, index($2," ")) }'
[^] # Re: Cleaner
Posté par Maxime (site web personnel) . Évalué à 1.
Du coup ça ne marche pas.
# wikisys
Posté par champix . Évalué à 3.
export LANG=C # Table header echo "^ Interface ^ MAC ^ IP ^ Masque ^ Network ^" # Parse ifconfig with awk, results one line per interface ifconfig | awk -F " *" ' # Each interface definition ends with an empty line, # even the last one. When an empty line is found we # print the results. $0 == "" { print iface" "mac" "ip" "masque iface = mac = ip = masque = "?" next } # Get interesting values $1 !~ /^ *$/ { iface = $1 } $2 ~ /^inet$/ { split( $3, a_res, ":" ); ip = a_res[2] } $4 ~ /^Mask:/ { split( $4, a_res, ":" ); masque = a_res[2] } $5 ~ /^Mask:/ { split( $5, a_res, ":" ); masque = a_res[2] } $4 == "HWaddr" { mac = $5 } ' | while read iface mac ip masque do # ipcalc gets network address and CIDR notation net=$( ipcalc -bn $ip"/"$masque | awk -F " *" '/Network:/ { print $2 }' ) # print each line echo '| '$iface' | '$mac' | '$ip' | '$masque' | '$net' |' doneEt Pour mettre en forme les routes de la manière suivante : J'utilise :LANG=C route -n | awk -F " *" ' NR == 2 { print "^ "$8" ^ "$1" ^ "$3" ^ "$2" ^ "; next } NR >=3 { print "| "$8" | "$1" | "$3" | "$2" |" } '# Attention à la gateway
Posté par Amand Tihon (site web personnel) . Évalué à 1.
Par exemple :
Suivre le flux des commentaires
Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.