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 :

R2cuperer l'adresse ip de plusieur ordinateurs


Sujet :

VBScript

  1. #1
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2013
    Messages : 4
    Points : 2
    Points
    2
    Par défaut R2cuperer l'adresse ip de plusieur ordinateurs
    Salam ,

    est ce qu'il existe un script vbs pour faire un ping sur le nom d'ordinateur de plusieurs poste qui sont situer dans un fichier texte, et d'avoir leurs adresse ip, dans un fichier sous format csv, avec comme info: nom du poste, adresse ip

    pour ceux que le ping n'a pas réussi, d'avoir comme résultat :"pas de réponse"

    Merci beaucoup

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    et bienvenue dans DVP
    Inspirez-vous de cette discussion et pondre votre code et si vous avez des problèmes alors poster votre code modifié et

  3. #3
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2013
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Merci pour votre réponse,
    je dois vous dire que je suis null en coté programmation, je ne sais pas comment spécifier que je veux comme résultat l'adresse ip seulement et non pas le résultat du test complet, voila ce que j'ai pu faire:*
    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
    Set objFSO = CreateObject("Scripting.FileSystemObject")
     
    Const ForReading = 1
    Const ForWriting = 2 
    Const ForAppending = 8
     
    Set objFile = objFSO.OpenTextFile("Liste_Machines.txt", ForReading, True)
     
    Set objRes = objFSO.OpenTextFile("Histo_ping.txt", ForAppending,True)
     
    Do While objFile.AtEndOfStream <> True  
     
    	Machine = objFile.ReadLine
     
    	'objRes.WriteLine (Machine)
     
    	Set WSHShell = CreateObject("WScript.Shell")
    	Set WshExec = WshShell.Exec("ping -n 1 -w 200 " & Machine)
     
    	PingResult = LCase(WshExec.StdOut.ReadAll)
     
     
    	If InStr(PingResult, "octets=") Then
    		'Ping OK
    		objRes.WriteLine (Machine & PingResult) 
    	Else
    		'Ping NOK
    		objRes.WriteLine (Machine & " NOK")
    	End If
     
     
    Loop
    Merci beaucoup pour votre aide

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut

    J'ai modifié un code déjà existant , donc à tester chez vous, en tenant compte qu'il existe déjà un fichier texte nommé : LISTE_PC.txt avec ce même script
    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
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    '*** Définition des variables globale ***
     
    Titre = "Ping de postes à distance @ Developpez.com"
    Const ForReading = 1, ForWriting = 8
    Public StrComputer, onlinestate, Fichier_log, WSHShell, Fichier_tmp, msg()
    Dim oFSO, oFl, ecr, lect, ComputerName
    Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set WSHShell = WScript.CreateObject("WScript.Shell")
    Set WSHNetwork = CreateObject("WScript.Network")
     
    ' *** Définition des variables d'environnement ***
     
    Liste_pc = "LISTE_PC.txt"
    Fichier_tmp = "LISTE_TMP.txt"
    Fichier_log = "RAPPORT_PING.txt"
     
    ' *** Définition des variables locales ***
     
    Redim msg(7)
    msg(0) = "__________________________________________"
    msg(1) = "Liste des postes introuvable " & dblquote(Liste_pc)
    msg(2) = "Aucun poste dans la liste " & dblquote(Liste_pc)
    msg(3) = "Début du script : "
    msg(4) = "Script interrompu : "
    msg(5) = "Fin du script : "
    msg(6) = " : Poste inaccessible"
    msg(7) = " : Accessible"
     
     
    ' *** Début du Script ***
     
    ' Test Fichier_Log existe
    If Not oFSO.FileExists(Fichier_log) Then oFSO.CreateTextFile(Fichier_log)
    Date_Heure = now
    Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(3) & Date_Heure & VbCrLf & VbCrLf : ecr.Close
     
    ' Test Liste_Pc existe
    If Not oFSO.FileExists(Liste_Pc) Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(1) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    End If
     
    ' Test Liste_Pc non vide
    Set oFl = oFSO.GetFile(Liste_Pc)
    If oFl.Size = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    End If
     
    ' Création Fichier_tmp
    if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    oFSO.CreateTextFile(Fichier_tmp)
     
    ' Correction de Liste_Pc en Fichier_tmp
     
    date_heure = now
    Set lect = oFSO.OpenTextFile(Liste_Pc, ForReading)
    Set ecr = oFSO.OpenTextFile(Fichier_tmp, ForWriting)
    While Not lect.AtEndOfStream
    	Texte = lect.ReadLine
    	Texte = Trim(Texte)
    	prem_car = lcase(left(Texte,1))
    	if ( Len(Texte) > 0 ) and InStr("'", prem_car) = 0 Then
    		ecr.Writeline Texte
    	End if	
    Wend
    lect.Close
    ecr.Close
     
    ' Test Fichier_tmp non vide
     
    Set oFl = oFSO.GetFile(Fichier_tmp)
    If oFl.Size = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    End If
     
    ' Lecture du Fichier_tmp
     
    Set lect = oFSO.OpenTextFile(Fichier_tmp, ForReading)
    st = lect.ReadAll
    ComputerName = Split(st, vbCrLf)
    lect.Close
     
    For i = lbound(ComputerName) to ubound(ComputerName) -1
    	strComputer = ComputerName(i)
    	Call Online
    	If onlinestate = 0 Then
    		Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(6) & VbCrLf : ecr.Close
    	Else
    		Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(7) & VbCrLf : ecr.Close
    	End if
    Next
     
    ' *** Fin du script
     
    Date_Heure = now
    Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(5) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
    if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    WSHShell.Run ("Notepad.exe " & Fichier_log)
    WScript.Quit
     
    ' *** Sous-Fonction Fin programme
     
    Sub fin_prog
    	Date_Heure = now
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(4) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
    	if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    	WSHShell.Run ("Notepad.exe " & Fichier_log)
    End Sub
     
    ' *** Sous-Fonction Ping
     
    Sub online
    	Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & StrComputer & "'")
    	For Each objStatus in objPing
    		If objStatus.Statuscode = 0 Then onlinestate = 1 else onlinestate = 0
    	Next
    End Sub
     
     
    ' *** Fonction Guillemets
     
    Function dblquote(strIn)
    	dblquote = Chr(34) & strIn & Chr(34)
    End Function

  5. #5
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2013
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Merci beaucoup pour votre aide,

    mais ce que je veux c'est d'avoir l'adresse ip, ce script m'affiche accessible ou non, ce que je veux c'est un truc du genre : nom_d'ordinateur ; adresse_ip


    Merci beaucoup

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Citation Envoyé par ciscoreseau Voir le message
    mais ce que je veux c'est d'avoir l'adresse ip, ce script m'affiche accessible ou non, ce que je veux c'est un truc du genre : nom_d'ordinateur ; adresse_ip

    Voici une petite fonction qui sert à extraire l'adresse ip de la hôte
    Donc essayez de l'intégrer dans le script principal
    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
    ExtractIP("Localhost")
    ExtractIP("www.yahoo.fr")
    ExtractIP("www.google.fr")
     
    Sub ExtractIP(PC)
        Titre = "Adresse ip de la hôte © Hackoo"
        Set Ws = CreateObject("wscript.Shell")
        Command = "Cmd /c ping "& PC &" > c:\pingtest.txt"
        Resultat = Ws.Run(Command,0,True)
        Set oFso = CreateObject("Scripting.FileSystemObject")
        If oFso.FileExists("c:\pingtest.txt") Then
            Set f = oFso.OpenTextFile("c:\pingtest.txt",1)
            Data = f.ReadAll
            f.Close
        Else
            MsgBox "une erreur s'est produite lors de la lecture du fichier c:\pingtest.txt",16,"Erreur de Lecture du fichier"
            Exit Sub
        End If
        Set objRegex = new RegExp
        objRegex.Pattern = "\b((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)\b"
        objRegex.Global = True
        objRegex.IgnoreCase = True
        Set Matches = objRegex.Execute(Data)
        MsgBox PC & ";"& Matches(0),64,Titre
    End Sub

  7. #7
    Membre averti
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Points : 304
    Points
    304
    Par défaut
    Bonjour !

    Cela doit donner quelquechose comme ça ...

    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
    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
    '*** Définition des variables globale ***
     
    Titre = "Adresses IP d'une liste de postes @ Developpez.com"
    Const ForReading = 1, ForWriting = 8
    Public StrComputer, onlinestate, Fichier_log, WSHShell, Fichier_tmp, msg()
    Dim oFSO, oFl, ecr, lect, ComputerName
    Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set WSHShell = WScript.CreateObject("WScript.Shell")
    Set WSHNetwork = CreateObject("WScript.Network")
     
    ' *** Définition des variables d'environnement ***
     
    Liste_pc = "LISTE_PC.txt"
    Fichier_tmp = "LISTE_TMP.txt"
    Fichier_log = "RAPPORT_IP.txt"
     
    ' *** Définition des variables locales ***
     
    Redim msg(6)
    msg(0) = "__________________________________________"
    msg(1) = "Liste des postes introuvable " & dblquote(Liste_pc)
    msg(2) = "Aucun poste dans la liste " & dblquote(Liste_pc)
    msg(3) = "Début du script : "
    msg(4) = "Script interrompu : "
    msg(5) = "Fin du script : "
    msg(6) = ";inaccessible"
     
     
    ' *** Début du Script ***
     
    ' Test Fichier_Log existe
    If Not oFSO.FileExists(Fichier_log) Then oFSO.CreateTextFile(Fichier_log)
    Date_Heure = now
    Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(3) & Date_Heure & VbCrLf & VbCrLf : ecr.Close
     
    ' Test Liste_Pc existe
    If Not oFSO.FileExists(Liste_Pc) Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(1) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    End If
     
    ' Test Liste_Pc non vide
    Set oFl = oFSO.GetFile(Liste_Pc)
    If oFl.Size = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    End If
     
    ' Création Fichier_tmp
    if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    oFSO.CreateTextFile(Fichier_tmp)
     
    ' Correction de Liste_Pc en Fichier_tmp
     
    date_heure = now
    Set lect = oFSO.OpenTextFile(Liste_Pc, ForReading)
    Set ecr = oFSO.OpenTextFile(Fichier_tmp, ForWriting)
    While Not lect.AtEndOfStream
    	Texte = lect.ReadLine
    	Texte = Trim(Texte)
    	prem_car = lcase(left(Texte,1))
    	if ( Len(Texte) > 0 ) and InStr("'", prem_car) = 0 Then
    		ecr.Writeline Texte
    	End if	
    Wend
    lect.Close
    ecr.Close
     
    ' Test Fichier_tmp non vide
     
    Set oFl = oFSO.GetFile(Fichier_tmp)
    If oFl.Size = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    End If
     
    ' Lecture du Fichier_tmp
     
    Set lect = oFSO.OpenTextFile(Fichier_tmp, ForReading)
    st = lect.ReadAll
    ComputerName = Split(st, vbCrLf)
    lect.Close
     
    For i = lbound(ComputerName) to ubound(ComputerName) -1
    	strComputer = ComputerName(i)
    	Call Online
    	If onlinestate = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(6) & VbCrLf : ecr.Close
    	Else
    	On error resume next
    	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
    	if err.number <> 0 then MsgBox "Vérifier que vous disposez des droits d'admin", VbOKOnly,"Erreur droits insuffisants" : Call fin_Prog : WScript.Quit
    	On error goto 0
    	strIPAddress = ""
    	Set colComputerIP = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration")
    	For Each IPConfig in colComputerIP
    	If Not IsNull(IPConfig.IPAddress) Then
    	For intIPCount = LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
    	strIPAddress = strIPAddress & IPConfig.IPAddress(intIPCount)
    	next
    	end if
    	Next
    		Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & ";" & strIPAddress & VbCrLf : ecr.Close
    	End if
    Next
     
    ' *** Fin du script
     
    Date_Heure = now
    Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(5) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
    if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    WSHShell.Run ("Notepad.exe " & Fichier_log)
    WScript.Quit
     
    ' *** Sous-Fonction Fin programme
     
    Sub fin_prog
    	Date_Heure = now
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(4) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
    	if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    	WSHShell.Run ("Notepad.exe " & Fichier_log)
    End Sub
     
    ' *** Sous-Fonction Ping
     
    Sub online
    	Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & StrComputer & "'")
    	For Each objStatus in objPing
    		If objStatus.Statuscode = 0 Then onlinestate = 1 else onlinestate = 0
    	Next
    End Sub
     
     
    ' *** Fonction Guillemets
     
    Function dblquote(strIn)
    	dblquote = Chr(34) & strIn & Chr(34)
    End Function

  8. #8
    Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2013
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Citation Envoyé par hackoofr Voir le message

    Voici une petite fonction qui sert à extraire l'adresse ip de la hôte
    Donc essayez de l'intégrer dans le script principal
    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
    ExtractIP("Localhost")
    ExtractIP("www.yahoo.fr")
    ExtractIP("www.google.fr")
     
    Sub ExtractIP(PC)
        Titre = "Adresse ip de la hôte © Hackoo"
        Set Ws = CreateObject("wscript.Shell")
        Command = "Cmd /c ping "& PC &" > c:\pingtest.txt"
        Resultat = Ws.Run(Command,0,True)
        Set oFso = CreateObject("Scripting.FileSystemObject")
        If oFso.FileExists("c:\pingtest.txt") Then
            Set f = oFso.OpenTextFile("c:\pingtest.txt",1)
            Data = f.ReadAll
            f.Close
        Else
            MsgBox "une erreur s'est produite lors de la lecture du fichier c:\pingtest.txt",16,"Erreur de Lecture du fichier"
            Exit Sub
        End If
        Set objRegex = new RegExp
        objRegex.Pattern = "\b((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)\b"
        objRegex.Global = True
        objRegex.IgnoreCase = True
        Set Matches = objRegex.Execute(Data)
        MsgBox PC & ";"& Matches(0),64,Titre
    End Sub
    Merci pour votre reponse;
    mais bon, ce code ne prend pas en entrer un fichier, et n'affiche pas en sortie le nom du poste suivi par son adresse ip, voici un utilitaire de nirsoft que j'ai trouvé d'ailleurs il est tres interessant, il se trouve dans cet url, http://www.nirsoft.net/utils/multiple_ping_tool.html

    Merci bcp pour votre aide et vos efforts

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Vous pouvez tester ce script aussi
    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
    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
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
        '*** Définition des variables globale ***
     
        Titre = "Ping d'une liste de postes @ Developpez.com"
        Const ForReading = 1, ForWriting = 8
        Public StrComputer, onlinestate, Fichier_log, WSHShell, Fichier_tmp, msg()
        Dim oFSO, oFl, ecr, lect, ComputerName
        Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
        Set WSHShell = WScript.CreateObject("WScript.Shell")
        Set WSHNetwork = CreateObject("WScript.Network")
     
        ' *** Définition des variables d'environnement ***
     
        Liste_pc = "LISTE_PC.txt"
        Fichier_tmp = "LISTE_TMP.txt"
        Fichier_log = "RAPPORT_PING.txt"
        Fichier_log_CSV = "RAPPORT_IP.csv"
     
        ' *** Définition des variables locales ***
     
        Redim msg(7)
        msg(0) = "__________________________________________"
        msg(1) = "Liste des postes introuvable " & dblquote(Liste_pc)
        msg(2) = "Aucun poste dans la liste " & dblquote(Liste_pc)
        msg(3) = "Début du script : "
        msg(4) = "Script interrompu : "
        msg(5) = "Fin du script : "
        msg(6) = " : Poste inaccessible"
        msg(7) = " : Accessible"
     
     
        ' *** Début du Script ***
     
        ' Test Fichier_Log existe
        If Not oFSO.FileExists(Fichier_log) Then oFSO.CreateTextFile(Fichier_log)
        Date_Heure = now
        Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(3) & Date_Heure & VbCrLf & VbCrLf : ecr.Close
     
        ' Test Liste_Pc existe
        If Not oFSO.FileExists(Liste_Pc) Then
           Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(1) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
        End If
     
        ' Test Liste_Pc non vide
        Set oFl = oFSO.GetFile(Liste_Pc)
        If oFl.Size = 0 Then
           Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
        End If
     
        ' Création Fichier_tmp
        if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
        oFSO.CreateTextFile(Fichier_tmp)
     
         ' Création Fichier_log_CSV
        if oFSO.FileExists(Fichier_log_CSV) Then oFSO.DeleteFile Fichier_log_CSV, True
        oFSO.CreateTextFile(Fichier_log_CSV)
     
        ' Correction de Liste_Pc en Fichier_tmp
     
        date_heure = now
        Set lect = oFSO.OpenTextFile(Liste_Pc, ForReading)
        Set ecr = oFSO.OpenTextFile(Fichier_tmp, ForWriting)
        While Not lect.AtEndOfStream
           Texte = lect.ReadLine
           Texte = Trim(Texte)
           prem_car = lcase(left(Texte,1))
           if ( Len(Texte) > 0 ) and InStr("'", prem_car) = 0 Then
              ecr.Writeline Texte
           End if   
        Wend
        lect.Close
        ecr.Close
     
        ' Test Fichier_tmp non vide
     
        Set oFl = oFSO.GetFile(Fichier_tmp)
        If oFl.Size = 0 Then
           Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
        End If
     
        ' Lecture du Fichier_tmp
     
        Set lect = oFSO.OpenTextFile(Fichier_tmp, ForReading)
        st = lect.ReadAll
        ComputerName = Split(st, vbCrLf)
        lect.Close
     
        For i = lbound(ComputerName) to ubound(ComputerName) -1
           strComputer = ComputerName(i)
           Call Online
           If onlinestate = 0 Then
              Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(6) & VbCrLf : ecr.Close
           Else
              ExtractIP(ComputerName(i))
     
           End if
        Next
     
        ' *** Fin du script
     
        Date_Heure = now
        Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(5) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
        if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
        WSHShell.Run ("Notepad.exe " & Fichier_log)
        WScript.Quit
     
        ' *** Sous-Fonction Fin programme
     
        Sub fin_prog
           Date_Heure = now
           Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(4) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
           if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
           WSHShell.Run ("Notepad.exe " & Fichier_log)
        End Sub
     
        ' *** Sous-Fonction Ping
     
        Sub online
           Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & StrComputer & "'")
           For Each objStatus in objPing
              If objStatus.Statuscode = 0 Then onlinestate = 1 else onlinestate = 0
           Next
        End Sub
     
     
        ' *** Fonction Guillemets
     
        Function dblquote(strIn)
           dblquote = Chr(34) & strIn & Chr(34)
        End Function
     
        Sub ExtractIP(PC)
        Titre = "Adresse ip de la hôte © Hackoo"
        Set Ws = CreateObject("wscript.Shell")
        Command = "Cmd /c ping "& PC &" > c:\pingtest.txt"
        Resultat = Ws.Run(Command,0,True)
        Set oFso = CreateObject("Scripting.FileSystemObject")
        If oFso.FileExists("c:\pingtest.txt") Then
            Set f = oFso.OpenTextFile("c:\pingtest.txt",1)
            Data = f.ReadAll
            f.Close
        Else
            MsgBox "une erreur s'est produite lors de la lecture du fichier c:\pingtest.txt",16,"Erreur de Lecture du fichier"
            Exit Sub
        End If
        Set objRegex = new RegExp
        objRegex.Pattern = "\b((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)\b"
        objRegex.Global = True
        objRegex.IgnoreCase = True
        Set Matches = objRegex.Execute(Data)
        'MsgBox PC & ";"& Matches(0),64,Titre
        Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write PC & ";"& Matches(0) & msg(7) & VbCrLf : ecr.Close
        Set CSV = oFSO.OpenTextFile(Fichier_log_CSV,ForWriting,True) : CSV.WriteLine PC & ";"& Matches(0) : CSV.Close
    End Sub

Discussions similaires

  1. Création réseau entre plusieurs ordinateurs
    Par FotoXe33 dans le forum Windows 7
    Réponses: 7
    Dernier message: 17/05/2010, 15h23
  2. Réponses: 3
    Dernier message: 14/02/2010, 10h06
  3. même adresse IP sur plusieurs interfaces réseaux
    Par crc16 dans le forum Développement
    Réponses: 0
    Dernier message: 04/02/2010, 13h23
  4. Comment découper une adresse postale en plusieurs parties
    Par arnaudperfect dans le forum Langage
    Réponses: 12
    Dernier message: 18/08/2008, 23h31
  5. Adresse IP de l'ordinateur
    Par Fred677 dans le forum Visual C++
    Réponses: 2
    Dernier message: 20/02/2008, 17h40

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