URL: https://linuxfr.org/forums/programmation-shell/posts/generateur-de-mots Title: Generateur de mots Authors: baberone Date: 2006年02月26日T18:46:13+01:00 Tags: Score: 0 Bonjour, j'ai produit un petit script qui génère tous les noms de domaine possible (enfin pas encore tout à fait) et fait un ping afin de connaitre l'addresse IP lié. Le script prend 2 variables et les utilise pour définir les tailles minimum et maximum des mots a générer. Je voudrai améliorer les script et je voulais avoir votre avis. Les commentaires sont en anglais mais je pense que ca devrai aller. merci! Voice le code: #!/bin/bash MINSIZE=1ドル MAXSIZE=2ドル array1=( a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 ) array2=( com net org be fr nl ) currsize=$MINSIZE #all sizes from MINSIZE to MAXSIZE echo "initial values MINSIZE $MINSIZE MAXSIZE $MAXSIZE" #loop through all posisble sizes. while [ $currsize -le $MAXSIZE ] do £spaces£ £/spaces£currpos=0 £spaces£ £/spaces£addr_gen="" £spaces£ £/spaces£arraysize=${#array1[@]} £spaces£ £/spaces£let "totalcombo=$arraysize**$currsize" £spaces£ £/spaces£echo "Total combo: $totalcombo $arraysize^$currsize" £spaces£ £/spaces£#loop through all combinations for this size £spaces£ £/spaces£for (( i = 0 ; i <= $totalcombo; i++ )) £spaces£ £/spaces£do £spaces£ £/spaces£lead="" £spaces£ £/spaces£#translate input decimal to arraysize base. The awk print should be optimized £spaces£ £/spaces£output=`echo "obase=$arraysize;ibase=10; $i;" | bc | awk '{print 1ドル 2ドル 3ドル 4ドル 5ドル 6ドル 7ドル 8ドル 9ドル 10ドル 11ドル 12ドル}'` £spaces£ £/spaces£#add leading zero £spaces£ £/spaces£for (( z = 1; z < $MAXSIZE; z++ )) £spaces£ £/spaces£do £spaces£ £/spaces£lead="00$lead" £spaces£ £/spaces£done £spaces£ £/spaces£output="$lead$output" £spaces£ £/spaces£#generate all combinations £spaces£ £/spaces£for (( j = 0 ; j < $currsize; j++ )) £spaces£ £/spaces£do £spaces£ £/spaces£let "startpos=(${#output}-(($j*2)))-1" £spaces£ £/spaces£substring=`expr substr "$output" $startpos 2` £spaces£ £/spaces£#substring=`printf "%d" $substring` £spaces£ £/spaces£substring=`awk 'BEGIN{printf "%d\n", ARGV[1];}' $substring` £spaces£ £/spaces£#echo "Output: $output size: ${#output} startpos: $startpos substr: $substring" £spaces£ £/spaces£addr_gen[$j]="${array1[$substring]}" £spaces£ £/spaces£done £spaces£ £/spaces£arraysize2=${#array2[@]} £spaces£ £/spaces£#try all different URL extensions £spaces£ £/spaces£for (( k = 0 ; k < $arraysize2 ; k ++ )) £spaces£ £/spaces£do £spaces£ £/spaces£#remove all spaces in the generated address £spaces£ £/spaces£finaladdr=`echo ${addr_gen[@]} | sed 's/ //g' ` £spaces£ £/spaces£#is there a faster way to resolve the name to the IP? £spaces£ £/spaces£ipvar=$(ping -c 1 www.$finaladdr.${array2[$k]} | grep PING | gawk '{print 3ドル}') £spaces£ £/spaces£echo "www.$finaladdr.${array2[$k]} -> $ipvar" £spaces£ £/spaces£done £spaces£ £/spaces£addr_gen="" £spaces£ £/spaces£done £spaces£ £/spaces£((currsize++)) done exit 0