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 :

Definition Variable en fonction de l'adresse IP


Sujet :

VBScript

  1. #1
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Avril 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hautes Pyrénées (Midi Pyrénées)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2017
    Messages : 3
    Points : 2
    Points
    2
    Par défaut Definition Variable en fonction de l'adresse IP
    Bonjour,

    Je suis nouveau dans le développement, et mon environnement étant Full Windows. Je suis en train de créer des GPO et un Logon script afin d'uniformiser mon parc machine.

    J'ai crée plusieurs VBS pour le déploiement de mes applications "socles", Ils fonctionnent parfaitement sur mon site principal.

    Je voudrais pouvoir utiliser cela sur un site distant disposant de son propre serveur de sources logicielles.

    Il nous arrive de préparer des postes à distance, avec notre compte administrateur. De ce fait, je souhaiterais définir la variable source en fonction de l'adresse IP du poste.

    Exemple :

    Site A = adresse IP 192.168.1.x = serveur de sources sitea.local
    Site B = adresse IP 192.168.2.x = serveur de sources siteb.local

    Je suis arrivé à la limite de mes capacités de développement, est il possible d'avoir quelques conseils ?

    Voici ce que j'ai commencé à écrire :

    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
    '
    ' Localisation des sources
    '
    strComputer = "."
     
    Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2" )
    Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True" )
    For Each objAdapter in colAdapters
        IPdebut = LBound(objAdapter.IPAddress)
        IPfin = UBound(objAdapter.IPAddress)
        If (objAdapter.IPAddress(IPdebut) <> "" ) then
            For i = IPdebut To IPfin
                    strIPAddress = objAdapter.IPAddress(i) & vbCrLf
            Next
        End If
    Next
     
    Public Function ip2num(IP) 'ipv4-only
    	Dim i, a, N
    	a = Split(ip, ".")
    	N = CDbl(0)
    	For i = 0 To UBound(a)
    	       N = N * 256 + a(i)
    Next
    ip2num = N
     
    End Function
     
    If ip2num(strIPAddress) >= ip2num("192.168.0.1")_
    And ip2num(strIPAddress) <= ip2num("1192.168.0.254") Then
     
    FusionSetupExe = "\\Srv-File\DEPLOY$\fusioninventory\fusioninventory-agent_windows-x64_" & AvailableVersion & ".exe"
     
    Elseif ip2num(strIPAddress) >= ip2num("192.168.1.1")_
    And ip2num(strIPAddress) <= ip2num("1192.168.1.254") Then
     
    FusionSetupExe = "\\Srv-File2\DEPLOY$\fusioninventory\fusioninventory-agent_windows-x64_" & AvailableVersion & ".exe"
     
    Else ip2num(strIPAddress) >= ip2num("192.168.3.1")_
    And ip2num(strIPAddress) <= ip2num("1192.168.3.254") Then
     
    FusionSetupExe = "\\Srv-File3\DEPLOY$\fusioninventory\fusioninventory-agent_windows-x64_" & AvailableVersion & ".exe"
     
    End If

  2. #2
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 201
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 201
    Points : 5 795
    Points
    5 795
    Par défaut
    Je te propose quelques chose de simple.
    J'ignore volontairement les problèmes de sous-réseau et d'IP multiples (la première trouvé qui match à gagné).

    Code vbscript : 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
    srv = FindServer()
    if (srv = "") Then
    	msgbox "Aucune serveur trouvé"
    Else
    	msgbox "Serveur : " & vbcrlf & srv
    End if
     
    Function FindServer()
    	FindServer = ""
    	Set objWMIService = GetObject("winmgmts:!\\.\root\cimv2" )
    	Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    	For Each objAdapter in colAdapters
    		ip = Join(objAdapter.IPAddress, ", ")
    		if (InStr(ip, "192.168.0.") = 1) Then
    			FindServer = "Srv-File"
    			Exit Function
    		ElseIf (InStr(ip, "192.168.1.") = 1) Then
    			FindServer = "Srv-File2"
    			Exit Function
    		ElseIf (InStr(ip, "192.168.3.") = 1) Then
    			FindServer = "Srv-File3"
    			Exit Function
    		End if
    	Next
    End Function

  3. #3
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Avril 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hautes Pyrénées (Midi Pyrénées)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2017
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    JE teste cela dés que possible

    Merci !!!

    Citation Envoyé par ericlm128 Voir le message
    Je te propose quelques chose de simple.
    J'ignore volontairement les problèmes de sous-réseau et d'IP multiples (la première trouvé qui match à gagné).

    Code vbscript : 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
    srv = FindServer()
    if (srv = "") Then
    	msgbox "Aucune serveur trouvé"
    Else
    	msgbox "Serveur : " & vbcrlf & srv
    End if
     
    Function FindServer()
    	FindServer = ""
    	Set objWMIService = GetObject("winmgmts:!\\.\root\cimv2" )
    	Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    	For Each objAdapter in colAdapters
    		ip = Join(objAdapter.IPAddress, ", ")
    		if (InStr(ip, "192.168.0.") = 1) Then
    			FindServer = "Srv-File"
    			Exit Function
    		ElseIf (InStr(ip, "192.168.1.") = 1) Then
    			FindServer = "Srv-File2"
    			Exit Function
    		ElseIf (InStr(ip, "192.168.3.") = 1) Then
    			FindServer = "Srv-File3"
    			Exit Function
    		End if
    	Next
    End Function

  4. #4
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Avril 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hautes Pyrénées (Midi Pyrénées)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2017
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    Bonjour,

    Cela fonctionne parfaitement je te remercie !

    TOP

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

Discussions similaires

  1. definition variable en référence dans fonction
    Par omelhor dans le forum Langage
    Réponses: 4
    Dernier message: 04/03/2012, 09h13
  2. Réponses: 6
    Dernier message: 06/01/2006, 20h55
  3. [PHP5] classe:sepration de la definition de la fonction
    Par rudyzuck dans le forum Langage
    Réponses: 8
    Dernier message: 15/12/2005, 11h38
  4. "class" vector à indice variable et fonction membr
    Par icetechnik dans le forum C++
    Réponses: 14
    Dernier message: 25/11/2005, 23h46
  5. changer et afficher une variable en fonction d'un select
    Par psychoBob dans le forum Général JavaScript
    Réponses: 30
    Dernier message: 22/11/2005, 08h15

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