fork download
  1. #!/bin/bash
  2. FICHIER_IP=[ethernet1]\nState=1\nName=Internet\nProtected=1\nMedia=0\nType=2\nGateway=\nAddress=125.246.235.245\nMask=255.0.0.0\nAddressComment=\n\n[ethernet2]\nState=2\nName=Intra\nProtected=1\nMedia=0\nType=2\nColor=1564521\n\n[ethernet3]\nState=1\nName=NET_IN\nProtected=1\nMedia=0\nType=1\nColor=FF0000\nGateway=124.128.200.100\nAddress=125.246.230.240\nMask=255.255.255.0\nAddressComment=\n\nIP_DYN=false\nLABEL_DHCP="DHCP"\nNOM_RESEAU=NET_IN\nLABEL_NOM=Name\=\n\nLABEL_ADRESSE=Address\nLABEL_MASQUE=Mask\nLABEL_PASSERELLE=Gateway\nLABEL_BLOC=ethernet\nLIGNE_NOM_RESEAU=`grep -i -n ^$LABEL_NOM$NOM_RESEAU`\nLIGNE_ENTETES=`grep -i -n $LABEL_BLOC $FICHIER_IP`;
  3. ADRESSE_IP=1.2.3.4
  4. MASQUE_IP=255.255.0.0
  5. PASSERELLE_IP=9.10.11.12
  6.  
  7. IP_DYN=false
  8. LABEL_DHCP="DHCP"
  9.  
  10. if [ -n "$ADRESSE_IP" ]
  11. then
  12. VAR_TEMP=`echo $ADRESSE_IP | grep -i '$LABEL_DHCP'`;
  13. if [ -n "$VAR_TEMP" ]
  14. then
  15. IP_DYN=true
  16. MASQUE_IP=""
  17. PASSERELLE_IP=""
  18. else
  19. VAR_TEMP=`echo $ADRESSE_IP | grep '^\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\).\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\).\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\).\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\)$'`;
  20. if [ -z "$VAR_TEMP" ]
  21. then
  22. echo "Le format de l'adresse IP est incorrect.";exit 1;
  23. fi
  24. fi
  25. fi
  26. if [ "$IP_DYN" == false ]
  27. then
  28. if [ -n "$MASQUE_IP" ]
  29. then
  30. VAR_TEMP=`echo $MASQUE_IP | grep '^\(255\|254\|252\|248\|240\|224\|192\|128\|0[0]\?[0]\?\).\(255\|254\|252\|248\|240\|224\|192\|128\|0[0]\?[0]\?\).\(255\|254\|252\|248\|240\|224\|192\|128\|0[0]\?[0]\?\).\(255\|254\|252\|248\|240\|224\|192\|128\|0[0]\?[0]\?$\)'`;
  31. if [ -z "$VAR_TEMP" ]
  32. then
  33. echo "Le format du masque IP est incorrect.";exit 1;
  34. else
  35. MASQUE1=`echo $MASQUE_IP | cut -d '.' -f1`
  36. MASQUE2=`echo $MASQUE_IP | cut -d '.' -f2`
  37. MASQUE3=`echo $MASQUE_IP | cut -d '.' -f3`
  38. MASQUE4=`echo $MASQUE_IP | cut -d '.' -f4`
  39. if [ $MASQUE1 -lt $MASQUE2 ] || [ $MASQUE2 -lt $MASQUE3 ] || [ $MASQUE3 -lt $MASQUE4 ]
  40. then
  41. echo "Le format du masque IP est incorrect.";exit 1;
  42. fi
  43. fi
  44. fi
  45. if [ -n "$PASSERELLE_IP" ]
  46. then
  47. VAR_TEMP=`echo $PASSERELLE_IP | grep '^\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\).\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\).\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\).\(25[0-5]\|2[0-4][0-9]\|[01]\?[0-9][0-9]\?\)$'`;
  48. if [ -z "$VAR_TEMP" ]
  49. then
  50. echo "Le format de la passerelle est incorrect.";exit 1;
  51. fi
  52. fi
  53.  
  54. if [ -z "$MASQUE_IP" ] || [ -z "$ADRESSE_IP" ] || [ -z "$PASSERELLE_IP" ]
  55. then
  56. echo "Il faut modifier a la fois l'adresse IP , le masque et la passerelle";exit 1;
  57. fi
  58. fi
  59. echo fin
Success #stdin #stdout 0.03s 5312KB
stdin
Standard input is empty
stdout
fin