IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Batch Config IP


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Janvier 2006
    Messages
    33
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 33
    Par défaut Batch Config IP
    Bonjour à tous

    J'essaie de faire un petit batch pour changer la conf IP.

    J'ai deja fait ca :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    echo on
    
    title "Changer la configuration IP"
    
    echo Changement de la Configuration IP vers la config FSU............
    
    netsh interface ip set address "Ethernet" static 192.168.11.10 255.255.255.0
    
    	if errorlevel 1 ( echo Probleme rencontré 
    	ipconfig
    echo.
    	set /p carte=Entrer le nom de la carte reseau : 
    	echo  nom de la carte : %carte%
    	netsh interface ip set address "%Carte%" static 192.168.11.10 255.255.255.0
    	)
    pause
    Mon premier problème est que ma variable Carte est vide!

    Second problème : J'aimerais lister les cartes réseaux et récuperer son nom par un index (plus simple pour l'utilisateur)
    ex : Carte dispo :
    1. Carte Wifi blablabla
    2. Carte Ethernet blablabla ...

    Merci d'avance pour les réponses

  2. #2
    Membre averti
    Inscrit en
    Janvier 2006
    Messages
    33
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 33
    Par défaut Script VBS config IP selon la carte réseau
    Bon j ai fait un script vbs qui permet de charger une config ip associée à une carte (choix de la carte possible)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    Msgbox "Cette application permet de switcher la config IP de la carte Réseau Ethernet" & chr(13) & _
    "entre l'adressage par DHCP et un adressage statique Compatible avec le FSU." & chr(13) & chr(13) & _
    "Version de soft : 1.0.1" & chr(13) & "Auteur : Michael VALLET",  vbinformation, "Infos"
    main
    Sub Main
    dim strComputer
    dim Carte(50)
    dim saisie
    dim i, j, a
    on error resume next
    strComputer = "."
    
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
    
    strIPAddress = Array("192.168.11.10")
    strSubnetMask = Array("255.255.255.0")
    'strGateway = Array("192.168.5.190")
    'strDNSServers = Array("97.20.255.254")
    strGatewayMetric = Array(1)
    
    carte(0) = ""
    i = 1
    
    For Each objNetAdapter in colNetAdapters
    	carte(i) = objNetAdapter.caption
    	i = i + 1
    Next
    i = i - 1
    
    for j = 1 to i
    	Carte(0) = carte(0) & j & " --> " & carte(j) & chr(13) & chr(13)
    next
    carte(0) = carte(0) & chr(13) & chr(13) & "Taper E pour ouvrir directement l'explorateur FSU"
    
    saisie = inputbox(carte(0),"Choix de la carte Réseau")
    	if saisie = "" then exit sub
    	'if saisie > i then main
    	if saisie = "E" or saisie = "e" then
    		Set WshShell = CreateObject("WScript.Shell")
    		Set oExec = WshShell.Exec("explorer \\192.168.11.11\Dossier_partager")
    		exit sub
    	end if
    ChoixConfig = inputbox("Quelle config voulez vous charger?" & chr(13) & chr(13) & "1 --> DHCP Alstom"  & chr(13) & "2 --> FSU","Choix de la Config IP")
    	if ChoixConfig = "" then exit sub
    	if choixConfig > 2 then main
    	
    If choixConfig = "1" then 
    	For Each objNetAdapter in colNetAdapters
    		if objNetAdapter.caption = carte(saisie) then
    		'msgbox objNetAdapter.caption & " ok, on rentre dans le IF"
    			errEnable = objNetAdapter.EnableDHCP 'EnableStatic(strIPAddress, strSubnetMask)
    			'errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    			'errDOM = objNetAdapter.EnableDNS'SetDNSServerSearchOrder(strDNSServers)
    		end if
    	next
    	if errEnable = 0 Then
    		WScript.Echo "L'addresse IP a été changée correctement."
    	Else
    		WScript.Echo "L'addresse n'a pas été changée il y a un Pb."
    	End If
    end if
    If choixConfig = "2" then 
    	For Each objNetAdapter in colNetAdapters
    		if objNetAdapter.caption = carte(saisie) then
    			WScript.Echo "L'ordinateur se connecte. Veuillez quelques secondes...."
    			errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    			'errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    			'errDOM = objNetAdapter.EnableDNS'SetDNSServerSearchOrder(strDNSServers)
    		end if
    	next
    	if errEnable = 0 Then
    		WScript.Echo "L'addresse IP a été changée correctement."
    		Set WshShell = CreateObject("WScript.Shell")
    		Set oExec = WshShell.Exec("explorer \\192.168.11.11\Dossier_partager")
    	Else
    		WScript.Echo "L'addresse n'a pas été changée il y a un Pb."
    	End If
    end if
    end sub

  3. #3
    Membre habitué
    Inscrit en
    Mai 2008
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 11
    Par défaut
    Salut,

    Ton script ne tourne pas sous windiws vista ? je l'éxécute ma carte réseau est bien trouvé j'entre E mais rien ne se passe ?

    Merci

  4. #4
    Membre éclairé
    Inscrit en
    Septembre 2006
    Messages
    84
    Détails du profil
    Informations forums :
    Inscription : Septembre 2006
    Messages : 84
    Par défaut
    Bonjour,

    Voici la commande qui te manque:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    netsh interface show interface
    Après pour le choix je te conseil d'aller du coté de "choice".Dernière chose, connexion réseau en batch s'écris "connexion r,seau", l'accent n'est pas pris en compte comme tel. Bonne continuation.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. logiciel config reseau en batch
    Par hamoji dans le forum Développement
    Réponses: 2
    Dernier message: 08/01/2014, 21h28
  2. [Batch] Initialiser les variables dun batch à partir d'un fichier de config
    Par mmahouac dans le forum Scripts/Batch
    Réponses: 4
    Dernier message: 24/07/2009, 14h52
  3. batch pour faire une sauvegarde
    Par bibiodp dans le forum Scripts/Batch
    Réponses: 4
    Dernier message: 13/08/2003, 13h09
  4. [JSP]Exécution d'un batch
    Par tsco_ops dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 17/07/2003, 14h58
  5. Verifier qu'un dossier existe (batch)
    Par kakou dans le forum Scripts/Batch
    Réponses: 2
    Dernier message: 08/01/2003, 13h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo