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

VBScript Discussion :

Script pour Changer l'adresse IP WIFI


Sujet :

VBScript

  1. #1
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut Script pour Changer l'adresse IP WIFI
    chers membres
    Bon j'ai trouvé ce script dans le Net pour changer automatiquemet l'adresse Ip Statique du réseau Wifi et l'adresse de proxy quand je me connecte avec mon LapTop au Travail.
    Bon le script marche Bien sauf que je cherche maintenant à faire un autre script pour remettre tous en ordre quand je me connecte depuis la maison sachant que l'adresse doit-être dynamique.
    de votre Aide
    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
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    ' Initialize Objects
         Dim LocalClass_StdRegProv: Set LocalClass_StdRegProv = GetObject("winmgmts:{impersonationlevel=impersonate}!//./root/default:StdRegProv")
         Dim EmptyRecordset: Set EmptyRecordset = CreateObject("ADODB.Recordset")
     ' Define Constants
         Const HKEY_CLASSES_ROOT = &H80000000, HKCR = &H80000000
         Const HKEY_CURRENT_USER = &H80000001, HKCU = &H80000001
         Const HKEY_LOCAL_MACHINE = &H80000002, HKLM = &H80000002
         Const HKEY_USERS = &H80000003, HKU = &H80000003
         Const HKEY_PERFORMANCE_DATA = &H80000004, HKPD = &H80000004
         Const HKEY_CURRENT_CONFIG = &H80000005, HKCC = &H80000005
         Const HKEY_DYN_DATA = &H80000006, HKDD = &H80000006
         Const MaxCharacters = 255
         Const adVarChar = 200
         Const adInteger = 3
     ' Dimension Public Variables
         Dim EntryNumber: EntryNumber = 0
         Dim Return
     
     EmptyRecordset.Fields.Append "Entry", adInteger
     EmptyRecordset.Fields.Append "Name", adVarChar, MaxCharacters
     EmptyRecordset.Fields.Append "Server", adVarChar, MaxCharacters
     EmptyRecordset.Fields.Append "Port", adInteger
     EmptyRecordset.Open
     
     ' Add server/port
         EntryNumber = EntryNumber + 1
         EmptyRecordset.AddNew
         EmptyRecordset("Entry") = EntryNumber
         EmptyRecordset("Name") = "Proxy 172.16.0.1:3128"
         EmptyRecordset("Server") = "172.16.0.1"
         EmptyRecordset("Port") = 3128
         EmptyRecordset.Update
     
         EntryNumber = EntryNumber + 1
         EmptyRecordset.AddNew
         EmptyRecordset("Entry") = EntryNumber
         EmptyRecordset("Name") = "Sans Proxy"
         EmptyRecordset("Server") = ""
         EmptyRecordset("Port") = 80
         EmptyRecordset.Update
     
     
     Dim Message
     EmptyRecordset.MoveFirst
     Do While EmptyRecordset.EOF = False
         Message = Message & EmptyRecordset("Entry").Value & "." & vbTab & EmptyRecordset("Name").Value & vbCrLf
         EmptyRecordset.MoveNext
     Loop
     
     Do
         Dim intAnswer: intAnswer = InputBox(Message, "Choisir une puis validez sur Ok", "1")
         If IsNumeric(intAnswer) = True Then intAnswer = CLng(intAnswer)
         If intAnswer > EmptyRecordset.RecordCount Or intAnswer < 0 Then WScript.Echo "Invalid entry, please try again..."
     Loop Until (((VarType(intAnswer) And vbLong) = vbLong) And intAnswer <= EmptyRecordset.RecordCount And intAnswer >= 0)
     
     Select Case True
         Case (intAnswer = 0)
             WScript.Echo "Cancelled. Exiting."
         Case (((VarType(intAnswer) And vbLong) = vbLong) And intAnswer <= EmptyRecordset.RecordCount And intAnswer > 0)
             EmptyRecordset.Filter = "Entry=" & intAnswer
             Dim ProxyServer: ProxyServer = EmptyRecordset("Server").Value & ":" & EmptyRecordset("Port").Value
             intAnswer = MsgBox("Would you like to set the proxy to " & EmptyRecordset("Name").Value & " (" & ProxyServer & ")?", vbQuestion + vbYesNo + vbSystemModal, "Confirm")
             If intAnswer = vbYes Then
                 Return = LocalClass_StdRegProv.SetDWORDValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 1)
                 Return = LocalClass_StdRegProv.SetStringValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", ProxyServer)
                 ChangeIP()
                 If Err.Number = 0 And Return = 0 Then
                     WScript.Echo "Proxy settings changed. Exiting."
                 Else
                     WScript.Echo "Proxy settings not changed. Exiting."
                 End If
             Else
                 WScript.Echo "No changes made. Exiting."
             End If
         Case Else
             WScript.Echo "Invalid entry. Exiting"
     End Select
     
     
     
    Sub ChangeIP() 
    strIP = Array("172.16.100.100")
    strmask = Array("255.255.255.0")
     
    strGateway = Array("")
    strGatewayMetric = Array(1)
     
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
    Set colNetAdapters = objWMIService.ExecQuery _
        ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
     
    For Each objNetAdapter in colNetAdapters
        errEnable = objNetAdapter.EnableStatic(strIP, strmask)
        errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
        If errEnable = 0 Then
            WScript.Echo "The IP address has been changed."
        Else
            WScript.Echo "The IP address could not be changed."
        End If
    Next
    End Sub

  2. #2
    Membre confirmé Avatar de pitchalov
    Homme Profil pro
    Inscrit en
    Avril 2007
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 340
    Points : 582
    Points
    582
    Par défaut
    Salut,

    Penche toi sur la méthode EnableDHCP de ton objet WMI Win32_NetworkAdapterConfiguration. En faisant les mêmes opérations, et en mettant EnableDHCP au lieu de EnableStatic, tu devrais retrouver ta configuration initiale.

    Bonne continuation.

  3. #3
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut
    Citation Envoyé par pitchalov Voir le message
    Salut,
    Penche toi sur la méthode EnableDHCP de ton objet WMI Win32_NetworkAdapterConfiguration. En faisant les mêmes opérations, et en mettant EnableDHCP au lieu de EnableStatic, tu devrais retrouver ta configuration initiale.
    Bonne continuation.
    pitchalov Problème et voila mon script final pour un reset de ma configuration càd retrouver ma configuration initiale avec désactivation du proxy et activation du DHCP
    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
    DesactiverProxy()
    ActiverDHCP()
     
    Sub DesactiverProxy()
    Set ws = createObject("wscript.Shell")
    ws.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0 , "REG_DWORD"
    End Sub
     
     Sub ActiverDHCP() 
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
    Set colNetAdapters = objWMIService.ExecQuery _
        ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
     
    For Each objNetAdapter in colNetAdapters
        errEnable = objNetAdapter.EnableDHCP()
        errGateways = objNetAdapter.SetGateways()
        If errEnable = 0 Then
            MsgBox "L'adresse IP a été bien changé et le DHCP est désormais Activé !" ,64, "Changer IP"
        Else
            MsgBox "L'adresse IP n'a pas été changé !" ,16, "Changer IP"
        End If
    Next
    End Sub

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

Discussions similaires

  1. Script pour changer la résolution de l'écran
    Par PoichOU dans le forum Windows
    Réponses: 1
    Dernier message: 30/12/2010, 18h14
  2. script pour changer le texte d'un div
    Par timaii dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 25/10/2007, 14h26
  3. Un script pour changer le password d'un utilisateur sans droit root.
    Par black.myst dans le forum Administration système
    Réponses: 2
    Dernier message: 03/02/2007, 15h30
  4. API pour changer l'adresse IP
    Par nunch dans le forum Windows
    Réponses: 6
    Dernier message: 05/01/2007, 15h17
  5. Script pour crypter une adresse email
    Par navis84 dans le forum Général JavaScript
    Réponses: 11
    Dernier message: 28/08/2006, 14h04

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