Script adresse IP + username des postes connectés au domaine

Résolu
samirsada Messages postés 8 Date d'inscription mercredi 8 mars 2006 Statut Membre Dernière intervention 5 décembre 2012 - 2 déc. 2008 à 18:15
samirsada Messages postés 8 Date d'inscription mercredi 8 mars 2006 Statut Membre Dernière intervention 5 décembre 2012 - 5 janv. 2009 à 10:50
Bonjour à toutes et à tous;

je cherche depuis quelques temps déjà, un script pour pinger une liste des Postes et le résultat et redirigé vers un fichier dans lequel on obtient l'adresse IP du poste le statut du Ping "En Ligne ou Hors Ligne" + le login de l'utilisateur actuel.

J’ai commencé à le créer mais il me manque les fonctions "username".
 D’autre part dans le script que j'ai créé la requête bloque si le poste ne répond pas au Ping donc mon résultat n'est pas complet, mon souhait et que si le PC n'est pas connecter ma requête passe au suivant afin de traiter toute ma liste. 

Voici le script que j'ai commencé à créer.

Merci d'avance pour votre réponse.




###################################################################################
Set shell = WScript.CreateObject("WScript.Shell")
set wshshell = wscript.createobject("wScript.shell")
set fso = createobject("scripting.filesystemobject")
curdir = wshshell.currentdirectory
set f = fso.OpenTextFile("D:\Test\PingGpo1.txt" ,1)
set f1 = fso.CreateTextFile("D:\Test\resultatping.txt" ,1)
f1.writeLine("Poste;ping;IP;username")
 strPoste = f.Readline
 Ping = WshShell.Run("ping -n 2 " & strPoste, 0, True)
 Select Case Ping
  Case 0
   strRPing = "En Ligne "
   Set objWMIService = GetObject ("winmgmts:\" & strPoste & "\root\cimv2")   Set colItems objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled True")
    For Each objItem in colItems
    'Wscript.Echo objItem.MACAddress
    For Each strAddress in objItem.IPAddress
     strRPing = strRPing & ";" & strAddress
    Next
   Next   
  Case 1
   strRping = "Hors Ligne"
 End Select
  strPing = strPoste & ";" & strRping & ";" & strSessionName
 f1.writeLine(strPing)
 
Loop


f.close()
f1.close()
##############################################################################""

sadallah samir 

7 réponses

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
23 déc. 2008 à 21:12
 Bonsoir,

L'exemple ci-dessous devrait t'inspirer.

Option Explicit
 
Dim objFso, objFile 
Dim strInFileTxt, strOutFileTxt, arrLineFicTxt, i
strInFileTxt = "D:\Test\PingGpo1.txt" 
strOutFileTxt = "D:\Test\resultatping.txt"

'Création d'un tableau contenant les lignes du fichier texte
arrLineFicTxt = FnReadFileTxt(strInFileTxt)

'Création fichier sortie avec ligne en-tête
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFile = objFso.CreateTextFile(strOutFileTxt ,1)
objFile.WriteLine("Poste;ping;IP;username")

'Parcours du tableau
For i = 0 To UBound(arrLineFicTxt)
    If arrLineFicTxt(i) <> vbNullString Then
       Call IsConnectable(Trim(arrLineFicTxt(i)), objFile) 
    End If     
Next

objFile.Close
Set objFile = Nothing
Set objFso = Nothing

WScript.Quit
'########################################################
Function FnReadFileTxt(ArgFile)
    Dim objFso, objFile, arrLineFicTxt
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFso.OpenTextFile(ArgFile, 1)
    'arrLineFicTxt est un tableau contenant toutes les lignes du .txt
    arrLineFicTxt = Split(objFile.ReadAll,vbCrLf)
    objFile.Close
   
    FnReadFileTxt = arrLineFicTxt
   
    Set objFile = Nothing
    Set objFso = Nothing
End Function
'########################################################
Sub IsConnectable(strComputer, objFile)
    On Error Resume Next
    Dim colAdapters, objAdapter
    Set colAdapters = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & _
                      strComputer).ExecQuery _
                      ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
    If Err.Number <> 0 Then
       objFile.WriteLine strComputer & ";" & False & ";IP inconnue;" & " UserName inconnu" 
    Else
       For Each objAdapter in colAdapters
           'WScript.Echo objAdapter.Description
           If InStr(objAdapter.Description,"WAN") Then  'objAdapter à modifier (test at home)
              Dim wshNetWork
              Set wshNetWork = CreateObject("WScript.NetWork")
              objFile.WriteLine strComputer & ";" & True & ";" & _
                                objAdapter.IPAddress(0) & ";" & wshNetWork.UserName
              Set wshNetWork = Nothing
              Exit For
           End if
       Next
    End If
    Set colAdapters = Nothing
End Sub
'########################################################

jean-marc
3
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
2 déc. 2008 à 23:09
Bonsoir,


Plusieurs possibilités pour tester la connexion d'un serveur.

exemple1:
' Vérification connexion réseau

' sHost = IP ou hostname

' iPings = nombre de tentative de ping

' iTo = attente en millisecondes entre 2 pings

'

Dim oShell, sHost, iPings, iTO

Set oShell  = CreateObject("WScript.Shell")

sHost    = "90.48.154.144"    'passerelle  ou IP   

iPings = 2

iTO    = 750


if IsConnectable(sHost, iPings, iTo) = False then

     ' On quitte si on est hors du réseau interne

     MsgBox "hors réseau"

     WScript.Quit -1

end If

Set oShell = Nothing

Set ExCmd = Nothing


Function IsConnectable(sHost,iPings,iTO)

     Set ExCmd = oShell.Exec("ping -n " & iPings & " -w " & iTO & " " & sHost)

    

     Select Case InStr(ExCmd.StdOut.Readall,"perte 0%")

            Case 0    IsConnectable = False

            Case Else IsConnectable = True

     End Select


End Function

MsgBox "connecté"

exemple2 (et 3):
'   Set Shell = WScript.CreateObject("WScript.Network")

strComputer = InputBox("saisir adresse IP",,"90.48.154.144")
'   strComputer = Shell.ComputerName

Counter = 0

On Error Resume Next


While Counter < 5   ' Teste la valeur du compteur.

      Counter = Counter + 1

      Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\")._

          ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")

      For Each objStatus in objPing

          If objStatus.Statuscode = 0 Then

             result = result & vbCr & "essai " & Counter & vbTab & "status= " & _

                         vbTab & objStatus.Statuscode & vbTab & "repond au ping !"

             else

             result = result & vbCr & "essai " & Counter & vbTab & "status= " & _

                         vbTab & objStatus.StatusCode & vbTab & "n'a pas repondu au ping!"

          End If

      Next

      Set objPing = Nothing

Wend   ' Fin de la boucle While lorsque Counter > 5.

'   Set Shell = Nothing


MsgBox result,,strComputer


jean-marc
0
samirsada Messages postés 8 Date d'inscription mercredi 8 mars 2006 Statut Membre Dernière intervention 5 décembre 2012
23 déc. 2008 à 12:19
Merci pour tes conseilles , cette méthode est intéressante .
Le but de ma demande est  de faire un script qui ping une liste des postes donnés et de me créer un fichier dans lequel il m'inscrit l'état du poste son adresse IP et le nom de l'utilisateur connecter a l'instant T

Merci

sadallah samir
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
23 déc. 2008 à 16:45
 Bonjour,

Et sous quelle forme est  << qui ping une liste des postes donnés >> ???

jean-marc
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
samirsada Messages postés 8 Date d'inscription mercredi 8 mars 2006 Statut Membre Dernière intervention 5 décembre 2012
23 déc. 2008 à 17:13
Alors comme indiquer dans mon script initial si vous regarder j'ai mis un chemin avec le nom d'un fichier qui contient la liste des postes
"set f = fso.OpenTextFile(" D:\Test\PingGpo1.txt " ,1)
set f1 = fso.CreateTextFile("D:\Test\resultatping.txt" ,1)
f1.writeLine("Poste;ping;IP;username")
 strPoste = f.Readline"

le script  va le parcourir ligne par ligne et a chaque ligne il lance un ping ensuite il m'écrit le résultat dans un autre fichier  ce dernier sera en format .TXT

merci pour votre aide

sadallah samir
0
samirsada Messages postés 8 Date d'inscription mercredi 8 mars 2006 Statut Membre Dernière intervention 5 décembre 2012
23 déc. 2008 à 17:14
Joyeux Noël et bonne année

sadallah samir
0
samirsada Messages postés 8 Date d'inscription mercredi 8 mars 2006 Statut Membre Dernière intervention 5 décembre 2012
5 janv. 2009 à 10:50
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ProgId" content="Word.Document" />
<meta name="Generator" content="Microsoft Word 11" />
<meta name="Originator" content="Microsoft Word 11" />
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CSSADAL%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Tableau Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
Bonne année meilleurs vœux pour cette année 2009, je vous
remercie pour votre aide, je vais adapter ce script, afin de le tester.


Je ne veux pas passer pour un lourd, mais je suis sur un petit projet qui
consiste a mettre en place un fichier Excel avec des marcos qui permet de créer
des comptes utilisateurs avec tous les informations qui vont avec "Nom,
Prénom, Login, MDP, OU, adresse de messagerie, N°ID, script de connexion, et
lecteur perso", avez vous un exemple de ce fichier, cela m'intéresse
beaucoup.

 

Encore merci





Sadallah Samir
0
Rejoignez-nous