Aide modification d'un batch pour la carte reseau

Aide modification d'un batch pour la carte reseau - Shell/Batch - Programmation

Marsh Posté le 13-03-2025 à 08:01:24    

Hello j'ai créer un point batch assez simple pour basculer d'un réseau a un autre simplement tout fonctionne bien mais voila maintenant j'aurais besoin de le faire évoluer car il se base sur le nom de la carte réseau hors en fonction d'ou je suis j'ai pas forcement le même adaptateur ( et donc le nom de carte réseau change) jusque la je changeait a chaque fois mais je voulais comment faire pour qu'un seul script gère les deux en fonction de la carte active? actuellement j'ai ceci mais il me faut soit le modifier soit deux script pour basculer a chaque fois de LAN a LAN 2 je me doute qu'il y a plsu simple mais je ne vois pas comment.
 

Code :
  1. @echo off
  2. set carte="LAN"
  3. set adrfixe=192.168.1.65
  4. set masque=255.255.255.0
  5. set carte2="LAN"
  6. set adrfixe2=10.0.10.3
  7. set masque2=255.0.0.0
  8. set carte3="LAN"
  9. set adrfixe3=192.168.168.65
  10. set masque3=255.255.255.0
  11. set carte4="LAN"
  12. set adrfixe4=10.1.10.11
  13. set masque4=255.0.0.0
  14. set passerelle4=10.1.10.12
  15. set carte5="LAN"
  16. set adrfixe5=192.168.0.11
  17. set masque5=255.255.255.240
  18. set passerelle5=192.168.0.1
  19. set carte6="LAN"
  20. set adrfixe6=172.31.255.100
  21. set masque6=255.255.255.0
  22. set passerelle6=172.31.255.1
  23. set carte7="LAN"
  24. set adrfixe7=192.168.1.10
  25. set masque7=255.255.255.0
  26. set passerelle7=192.168.1.1
  27. set dns=8.8.8.8
  28. set carte8="LAN"
  29. set adrfixe8=192.0.2.11
  30. set masque8=255.255.255.0
  31. set passerelle8=192.0.2.1
  32. :question
  33. SET /P lan=Adressage IP   1/ DCHP    2/ 192.168.1.65     3/ 10.0.10.3    4/ 192.168.168.65    5/ 10.1.10.11     6/ 192.168.0.11  7/ 172.31.255.100  8/192.168.1.10 9/192.0.2.11 10/ QUITTER (1/2/3/4/5/6/7/8/9)? :
  34. if %lan%==1 goto IPDHCP
  35. if %lan%==2 goto IPfixe
  36. if %lan%==3 goto IPfixe2
  37. if %lan%==4 goto IPfixe3
  38. if %lan%==5 goto IPfixe4
  39. if %lan%==6 goto IPfixe5
  40. if %lan%==7 goto IPfixe6
  41. if %lan%==8 goto IPfixe7
  42. if %lan%==9 goto IPfixe8
  43. if %lan%==10 goto Nfin
  44. goto question
  45. :IPfixe8
  46. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe8% (O/N)? :
  47. if %lan%==o goto OKFixe8
  48. if %lan%==O goto OKFixe8
  49. if %lan%==n goto Nfin
  50. if %lan%==N goto Nfin
  51. goto IPfixe8
  52. :IPfixe7
  53. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe7% (O/N)? :
  54. if %lan%==o goto OKFixe7
  55. if %lan%==O goto OKFixe7
  56. if %lan%==n goto Nfin
  57. if %lan%==N goto Nfin
  58. goto IPfixe7
  59. :IPfixe6
  60. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe6% (O/N)? :
  61. if %lan%==o goto OKFixe6
  62. if %lan%==O goto OKFixe6
  63. if %lan%==n goto Nfin
  64. if %lan%==N goto Nfin
  65. goto IPfixe6
  66. :IPfixe5
  67. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe5% (O/N)? :
  68. if %lan%==o goto OKFixe5
  69. if %lan%==O goto OKFixe5
  70. if %lan%==n goto Nfin
  71. if %lan%==N goto Nfin
  72. goto IPfixe5
  73. :IPfixe4
  74. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe4% (O/N)? :
  75. if %lan%==o goto OKFixe4
  76. if %lan%==O goto OKFixe4
  77. if %lan%==n goto Nfin
  78. if %lan%==N goto Nfin
  79. goto IPfixe4
  80. :IPfixe3
  81. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe3% (O/N)? :
  82. if %lan%==o goto OKFixe3
  83. if %lan%==O goto OKFixe3
  84. if %lan%==n goto Nfin
  85. if %lan%==N goto Nfin
  86. goto IPfixe3
  87. :IPfixe2
  88. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe2% (O/N)? :
  89. if %lan%==o goto OKFixe2
  90. if %lan%==O goto OKFixe2
  91. if %lan%==n goto Nfin
  92. if %lan%==N goto Nfin
  93. goto IPfixe2
  94. :IPfixe
  95. SET /P lan=confirmer l'adressage en IP Fixe %adrfixe% (O/N)? :
  96. if %lan%==o goto OKFixe
  97. if %lan%==O goto OKFixe
  98. if %lan%==n goto Nfin
  99. if %lan%==N goto Nfin
  100. goto IPfixe
  101. :OKFixe
  102. netsh interface ipv4 set address %carte% static %adrfixe% %masque% 
  103. netsh inter ipv4 delete dnsservers LAN all > nul
  104. goto Ofin
  105. :OKFixe2
  106. netsh interface ip set address %carte2% static %adrfixe2% %masque2% 
  107. netsh inter ip delete dnsservers LAN all > nul
  108. goto Ofin
  109. :OKFixe3
  110. netsh interface ip set address %carte3% static %adrfixe3% %masque3% 
  111. netsh inter ip delete dnsservers LAN all > nul
  112. goto Ofin
  113. :OKFixe4
  114. netsh interface ip set address %carte4% static %adrfixe4% %masque4% %passerelle4%
  115. netsh inter ip delete dnsservers LAN all > nul
  116. goto Ofin
  117. :OKFixe5
  118. netsh interface ip set address %carte5% static %adrfixe5% %masque5% %passerelle5%
  119. netsh inter ip delete dnsservers LAN all > nul
  120. goto Ofin
  121. :OKFixe6
  122. netsh interface ip set address %carte6% static %adrfixe6% %masque6% %passerelle6%
  123. netsh inter ip delete dnsservers LAN all > nul
  124. goto Ofin
  125. :OKFixe7
  126. netsh interface ip set address %carte7% static %adrfixe7% %masque7% %passerelle7%
  127. netsh interface ip set address %carte7% dns %dns%
  128. goto Ofin
  129. :OKFixe8
  130. netsh interface ip set address %carte8% static %adrfixe8% %masque8% %passerelle8%
  131. netsh interface ip set address %carte8% dns %dns%
  132. goto Ofin
  133. :IPDHCP
  134. SET /P lan=confirmer l'adressage en IP Dynamique (O/N)? :
  135. if %lan%==o goto OKDHCP
  136. if %lan%==O goto OKDHCP
  137. if %lan%==n goto Nfin
  138. if %lan%==N goto Nfin
  139. goto IPDHCP
  140. :OKDHCP
  141. netsh interface ip set address %carte% dhcp
  142. netsh inter ip delete dnsservers LAN all > nul
  143. netsh inter ip set dnsservers LAN dhcp > nul
  144. goto Ofin
  145. :Nfin
  146. @echo Aucune modification n'a ete appliquee
  147. @echo -
  148. SET /P lan=appuyez sur [ENTREE] pour quitter
  149. goto fin
  150. :Ofin
  151. @echo La nouvelle configuration vient d'etre appliquee
  152. @echo -
  153. SET /P lan=appuyer sur [ENTREE] pour quitter
  154. goto fin
  155. :fin

Reply

Marsh Posté le 13-03-2025 à 08:01:24   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed