Adresse IP et nom utilisateur connectés sur un server
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 2018
-
12 mai 2007 à 14:46
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 2018
-
14 mai 2007 à 13:41
Bonjour à tous
Suite à une question de "[auteurdetail.aspx?ID= 1056766 sampapaya]" sur une de mes sources, je viens d'écrire un petit script (vbs)
qui énumère les utilisateurs connectés sur un frontal (+domaine).
Option Explicit
Dim objDomaine, objUser
Dim strListe, strResult, cpt
Set objDomaine = GetObject("WinNT://DomaineTartempion")
objDomaine.Filter = Array("computer") ' "user","computer","group"
For Each objUser In objDomaine
strListe = ""
Call fnAddressIP(objUser.Name)
If strListe <> "" Then
strResult = strResult &vbCrLf& strListe
cpt = cpt + 1
End If
Next
Set objDomaine = Nothing
WScript.Echo "Utilisateurs connectés (" & cpt & ")" &vbCrLf& strResult
Function fnAddressIP(strComputer)Const Separateur1 "[", Separateur2 "]"
Dim objShell, objScriptExec
Dim StrPingResults, strNewChaine, iPos1, iPos2
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & strComputer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "perdus = 0") Then
iPos1 = InStr(1, strPingResults, Separateur1)
If iPos1 <> 0 Then
strNewChaine = Mid(Right(strPingResults, _
Len(strPingResults) - iPos1 +1), Len(Separateur1 )+1)
iPos2 = InStr(1, strNewChaine, Separateur2)
If iPos2 <> 0 Then
strListe = Left(strNewChaine, iPos2-1) &vbTab& strComputer
fnAddressIP = strListe
End If
End If
End If
Set objShell = Nothing
Set objScriptExec = Nothing
End Function
----------------------------------------
Questions:
- Est-ce une bonne méthode ??? ;
- Peut-on masquer la fenêtre dos du objShell.Exec ???
Dautre part, j'ai testé un ping wmi, mais je n'ai pas trouvé la fonction pour afficher l'IP.
Function fnPingUser(strComputer)
On Error Resume Next
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\")._
ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If objStatus.Statuscode = 0 Then
'WScript.Echo objStatus.Address &vbTab& strComputer
'MsgBox "status= " & objStatus.Statuscode,vbInformation,strComputer & " repond au ping !"
strListe = strComputer &vbTab& " repond au ping " &vbTab& " status= " & objStatus.Statuscode
'Call fnAddressIP(strComputer)
fnPingUser = strListe
End If
Next
Set objPing = Nothing
End Function
Mes 2 tests (fnAddressIP et fnPingUser) prennent plusieurs minutes.
Merci pour vos remarques et/ou suggestions.
jean-marc
A voir également:
Adresse IP et nom utilisateur connectés sur un server
Function fnUsersConnected()
Dim objShell, objScriptExec
Dim arrTabUsers, i
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("net view")
For i=0 To UBound(arrTabUsers)
arrTabUsers(i) = Split(arrTabUsers(i)," ")
strListe = strListe &vbCrLf& Replace(arrTabUsers(i)(0),"\","")
cpt = cpt + 1
Next
fnUsersConnected = strListe & cpt
Set objShell = Nothing
Set objScriptExec = Nothing
End Function
Par contre, je n'ai rien trouvé d'autres que le ping pour déterminer l'IP.
Donc, si quelqu'un a une idée .... merci.