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 :

paramétrage d'une Interface réseau [Batch]


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    cherche poste technicien réseau/ maintenance
    Inscrit en
    Août 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haute Saône (Franche Comté)

    Informations professionnelles :
    Activité : cherche poste technicien réseau/ maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2015
    Messages : 3
    Par défaut paramétrage d'une Interface réseau
    Bonjour,

    Je souhaiterai savoir comment faire pour créer un script qui change les paramètres DNS automatiquement en reconnaissant le nom de l'interface physique qui est câblée.
    Mon souci est de faire en sorte à ce qu'il reconnaisse la bonne interface Ethernet. Pour ce qui est du changement de DNS j'utilise netsh.
    J'ai des postes sous Windows 7 et 10 avec 1 à 2 interface Ethernet (une seule est branchée) plus une interface pour le Wifi.

    Merci d'avance pour vos réponses

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    J'ai un vbscript tout prêt qui change les DNS en OpenDNS
    Si vous voulez le tester je vais le chercher pour vous ?

  3. #3
    Futur Membre du Club
    Homme Profil pro
    cherche poste technicien réseau/ maintenance
    Inscrit en
    Août 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haute Saône (Franche Comté)

    Informations professionnelles :
    Activité : cherche poste technicien réseau/ maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2015
    Messages : 3
    Par défaut
    Citation Envoyé par hackoofr Voir le message

    J'ai un vbscript tout prêt qui change les DNS en OpenDNS
    Si vous voulez le tester je vais le chercher pour vous ?
    Bonsoir.
    Je veux bien regarder vote script.
    Merci beaucoup

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    OpenDNS_Admin-Rights.vbs
    Code vb : 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
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    Option Explicit
    Dim MessageArabe,MessageFr,MessageEn,Titre,Question,strComputer,objWMIService,colNetCards,objNetCard,arrDNSServers
    MessageArabe = ChrW(1607)&ChrW(1604)&ChrW(32)&ChrW(1578)&ChrW(1585)&ChrW(1610)&ChrW(1583)&ChrW(32)&_
    ChrW(1581)&ChrW(1580)&ChrW(1576)&ChrW(32)&ChrW(1575)&ChrW(1604)&_
    ChrW(1605)&ChrW(1608)&ChrW(1575)&ChrW(1602)&ChrW(1593)&ChrW(32)&ChrW(1575)&ChrW(1604)&_
    ChrW(1575)&ChrW(1576)&ChrW(1575)&ChrW(1581)&ChrW(1610)&ChrW(1577)&ChrW(32)&ChrW(1608)&_
    ChrW(32)&ChrW(1575)&ChrW(1604)&ChrW(1582)&ChrW(1576)&ChrW(1610)&ChrW(1579)&ChrW(1577)
    MessageFr = " Voulez-vous bloquer les sites pornographiques et malveillants avec le service OpenDNS ?"
    MessageEn = " Do you want to block pornographic and malicious websites with the OpenDNS Service ?"
    Titre = MessageArabe &" © Hackoo © 2016"
     
    If Not WScript.Arguments.Named.Exists("elevate") Then
      CreateObject("Shell.Application").ShellExecute WScript.FullName _
        , WScript.ScriptFullName & " /elevate", "", "runas", 1
      WScript.Quit
    End If
     
    If AppPrevInstance() Then   
        MsgBox "Il y a une instance déjà en cours",VbExclamation,"Il y a une instance déjà en cours"    
        WScript.Quit   
    Else   
        Call ListDNSInfo()
    End If   
    '****************************************************************************************************************
    Question = MsgBox(MessageArabe  & VbcrLf & MessageFr & VbcrLf & MessageEn,vbYesNoCancel+VbQuestion,Titre)
    If Question = VbYes then
        Call OpenDNS(True)
    End if
    If Question = VbNo Then
        Call OpenDNS(False)
    Else
        Call ListDNSInfo()
        wscript.quit
    End if
    '****************************************************************************************************************
    Sub OpenDNS(Active)
        Dim OKMsgAR,OKMsgFR,OKMsgEN,NoOKMsgAR,NoOKMsgFR,NoOKMsgEN
        OKMsgAR = ChrW(1578)&ChrW(1605)&ChrW(32)&ChrW(1578)&ChrW(1606)&ChrW(1588)&ChrW(1610)&ChrW(1591)&ChrW(32)&ChrW(1582)&_
        ChrW(1583)&ChrW(1605)&ChrW(1577)&ChrW(32)&ChrW(1571)&ChrW(1576)&ChrW(1606)&ChrW(1583)&ChrW(1606)&ChrW(1587)&ChrW(32)&_
        ChrW(1576)&ChrW(1606)&ChrW(1580)&ChrW(1575)&ChrW(1581)&ChrW(33)
     
        NoOKMsgAR = ChrW(1578)&ChrW(1605)&ChrW(32)&ChrW(1573)&ChrW(1604)&ChrW(1594)&ChrW(1575)&ChrW(1569)&ChrW(32)&ChrW(1582)&_
        ChrW(1583)&ChrW(1605)&ChrW(1577)&ChrW(32)&ChrW(1571)&ChrW(1576)&ChrW(1606)&ChrW(1583)&ChrW(1606)&ChrW(1587)&ChrW(32)&_
        ChrW(1576)&ChrW(1606)&ChrW(1580)&ChrW(1575)&ChrW(1581)&ChrW(33)
     
        OKMsgFR = "Le service OpenDNS est activé avec succès !"
        NoOKMsgFR = "Le service OpenDNS est désactivé avec succès !"
     
        OKMsgEN = "The OpenDNS service is successfully activated !"
        NoOKMsgEN = "The OpenDNS service is off successfully !"
        On Error Resume Next
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
        Set colNetCards = objWMIService.ExecQuery _
        ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
        If Active = True Then
            For Each objNetCard in colNetCards
                arrDNSServers = Array("208.67.222.123", "208.67.220.123")
                objNetCard.SetDNSServerSearchOrder(arrDNSServers)
                If Err = 0 Then
                    MsgBox OKMsgAR & VbCrlF & OKMsgFR & VbCrlF & OKMsgEN,VbInformation, OKMsgAR & OKMsgFR
                    Call ListDNSInfo()
                    Call CheckOpenDNS()
                Else
                    MsgBox Err.Description,Vbcritical,Err.Description
                End If    
            Next
        Else
            For Each objNetCard in colNetCards
                objNetCard.SetDNSServerSearchOrder(null)
                If Err = 0 Then
                    MsgBox NoOKMsgAR & VbCrlF & NoOKMsgFR & VbCrlF & NoOKMsgEN,VbExclamation,NoOKMsgAR & NoOKMsgFR
                    Call ListDNSInfo()
                    Call CheckOpenDNS()
                Else
                    MsgBox Err.Description,Vbcritical,Err.Description
                End If    
            Next
        End If
    End Sub
    '****************************************************************************************************************
    Sub CheckOpenDNS()
        Dim Ws,OpenDNS_URL
        Set Ws = CreateObject("Wscript.Shell")
        OpenDNS_URL = "IEXPLORE https://www.opendns.com/welcome/"
        ws.run OpenDNS_URL
    End Sub
    '*****************************************************************************************************************
    Sub ListDNSInfo()
        Dim ComputerName,IPConfigSet,IPConfig,BailObtenu,BailExpirant
        ComputerName="."
        On error resume next 
        set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & ComputerName).ExecQuery _ 
        ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE") 
        If Err.Number<>0 Then 
            wscript.echo " - non accessible -" 
        Else 
            for each IPConfig in IPConfigSet 
     
                BailObtenu = IPConfig.DHCPLeaseObtained
                BailExpirant = IPConfig.DHCPLeaseExpires
     
    '---- Convertion des date et heure d'obtention et d'expiration des baux DHCP en un format lisible par l'utilisateur. ----
                BailObtenu = mid(BailObtenu, 7, 2) & "/" & mid(BailObtenu, 5, 2) & "/" & mid(BailObtenu, 1, 4) & " - " & mid(BailObtenu, 9, 2)& ":" & mid(BailObtenu, 11, 2)& ":" & mid(BailObtenu, 13, 2)
                BailExpirant = mid(BailExpirant, 7, 2) & "/" & mid(BailExpirant, 5, 2) & "/" & mid(BailExpirant, 1, 4) & " - " & mid(BailExpirant, 9, 2)& ":" & mid(BailExpirant, 11, 2)& ":" & mid(BailExpirant, 13, 2)
     
                MsgBox " Configuration réseau de l'ordinateur " & ComputerName & vbcrlf & vbcrlf & _ 
                "Nom Machine " & vbtab & " : " & IPConfig.DNSHostName & vbcrlf & _ 
                "Carte active" & vbtab & " : " & IPConfig.Description & vbcrlf & _ 
                "Adresse MAC " & vbtab & " : " & IPConfig.MACAddress & vbcrlf & _ 
                "DHCP Activé" & vbtab & " : " & IPConfig.DHCPEnabled & vbcrlf & _
                "Adresse IP " & vbtab & " : " & IPConfig.IPAddress(0) & vbcrlf & _
                "Masque " & vbtab & vbtab & " : " & IPConfig.IPSubnet(0) & vbcrlf & _
                "Passerelle     " & vbtab & " : " & IPConfig.DefaultIPGateway(0) & vbcrlf & _     
                "Serveur DHCP " & vbtab & " : " & IPConfig.DHCPServer & vbcrlf & vbcrlf & _
                "Serveur DNS " & vbtab & " : " & IPConfig.DNSServerSearchOrder(0) & vbcrlf & _
                "             " & vbtab & vbtab & " : " & IPConfig.DNSServerSearchOrder(1) & vbcrlf & _
                "Serveur WINS " & vbtab & " : " & IPConfig.WINSPrimaryServer(0) & vbcrlf & _
                "             " & vbtab & vbtab & " : " & IPConfig.WINSSecondaryServer(0) & vbcrlf & vbcrlf & _
                " Bail obtenu " & vbtab & " : " & BailObtenu & vbcrlf & _
                " Bail expirant " & vbtab & " : " & BailExpirant _                    
                ,VbInformation,"Configuration réseau de l'ordinateur " 
            Next 
        End If
    End Sub
    '**************************************************************************
    Function AppPrevInstance()   
        With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")   
            With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
                " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")   
                AppPrevInstance = (.Count > 1)   
            End With   
        End With   
    End Function   
    '**************************************************************************
    Function CommandLineLike(ProcessPath)   
        ProcessPath = Replace(ProcessPath, "\", "\\")   
        CommandLineLike = "'%" & ProcessPath & "%'"   
    End Function
    '**************************************************************************

  5. #5
    Futur Membre du Club
    Homme Profil pro
    cherche poste technicien réseau/ maintenance
    Inscrit en
    Août 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haute Saône (Franche Comté)

    Informations professionnelles :
    Activité : cherche poste technicien réseau/ maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2015
    Messages : 3
    Par défaut
    Merci beaucoup je vais étudier le code.

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

Discussions similaires

  1. Définir une interface réseau par défaut pour Internet
    Par alavoler dans le forum Windows 7
    Réponses: 6
    Dernier message: 19/11/2011, 12h00
  2. Réponses: 7
    Dernier message: 21/04/2011, 18h37
  3. Réponses: 5
    Dernier message: 24/01/2011, 22h17
  4. Probleme up d'une interface réseau
    Par lcfseth dans le forum Réseau
    Réponses: 1
    Dernier message: 19/08/2010, 11h34
  5. Réponses: 3
    Dernier message: 03/11/2009, 17h55

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