VBScript ping

Bonjour developpant actuellement un petit script en vbs j ai besoin de pinger une plage d ip pas de soucis pour la boucle ou pour les option mon seul pb est d integrer une commande ping dans le script et dans recuperer le resultat sous forme de valeur booleene! voila j ai essayer des tas de solution mais la je bloque

merci d avance pour vos reponse!

Ce topic devrait t’être utile: http://www.developpez.net/forums/showthread.php?t=205832

Et sinon c’est pour tester si un PC marche sur le réseau? Parce que si c’est ça il suffit simplement de se connecter via WMI pour tester.

Merci beaucoup mais personnellement j ai utiliser quelque chose comme sa:


Set WshExec = WshShell.Exec("ping -n 1 -w 500 " & strComputer) 'send 1 echo requests, waiting half secs 
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
...

cependant je recherche des liens sur wmi notament pour ressortir le hostname a partir de l adresse IP ( je profite du moment car je n ai pas encore réaliser mes recherche.)

si quelqu’un possede quelque un de ces liens sa serais simpa encore merci et a bientot!

Pour récuper le hostname depuis une ip, en VB je fait comme ça :

(dans un module)


Option Explicit

Public Enum WinsockVersion
    SOCKET_VERSION_11 = &H101
    SOCKET_VERSION_22 = &H202
End Enum

Public Const WSADESCRIPTION_LEN = 257
Public Const WSASYS_STATUS_LEN = 129

Public Const INADDR_NONE = &HFFFF
Public Const AF_INET = 2

Public Const NI_MAXHOST = 1025
Public Const NI_MAXSERV = 32
Public Const NI_NUMERICSERV = &H8

Public Type sockaddr_in
    sin_family       As Integer
    sin_port         As Integer
    sin_addr         As Long
    'sin_addr        As in_addr
    sin_zero(1 To 8) As Byte
End Type

Public Type WSAData
    wVersion       As Integer
    wHighVersion   As Integer
    szDescription  As String * WSADESCRIPTION_LEN
    szSystemStatus As String * WSASYS_STATUS_LEN
    iMaxSockets    As Integer
    iMaxUdpDg      As Integer
    lpVendorInfo   As Long
End Type

Public Declare Function inet_addr Lib "ws2_32.dll" (ByVal cp As String) As Long
Public Declare Function htons Lib "ws2_32.dll" (ByVal hostshort As Integer) As Integer
Public Declare Function getnameinfo Lib "ws2_32.dll" (sa As sockaddr_in, ByVal salen As Long, ByVal host As String, ByVal hostlen As Long, ByVal serv As String, ByVal servlen As Long, ByVal flags As Long) As Long

Public Declare Function WSAStartup Lib "ws2_32.dll" (ByVal wVR As Long, lpWSAD As WSAData) As Long
Public Declare Function WSACleanup Lib "ws2_32.dll" () As Long

Function GetHostnameByAddr(ByVal sz_ip As String, ByVal port As Integer) As String
Dim si As sockaddr_in
Dim ret As Long
Dim hostname As String
Dim servInfo As String

    si.sin_family = AF_INET
    si.sin_addr = inet_addr(sz_ip)
    si.sin_port = htons(port)
    
    hostname = Space(NI_MAXHOST)
    servInfo = Space(NI_MAXSERV)
    ret = getnameinfo(si, LenB(si), hostname, NI_MAXHOST, servInfo, NI_MAXSERV, NI_NUMERICSERV)
    If ret = 0 Then
        GetHostnameByAddr = hostname
    Else
        GetHostnameByAddr = "NULL"
    End If
    
End Function

Public Function InitializeWinsock(Version As WinsockVersion) As Long
Dim udtWinsockData  As WSAData

    InitializeWinsock = WSAStartup(Version, udtWinsockData)
End Function

(Dans une form ou n’importe ou d’ailleurs)


Private Sub Form_Load()

    If InitializeWinsock(SOCKET_VERSION_22) > 0 Then
        MsgBox ("Winsock Init Error !")
        End
    End If
    
    MsgBox (GetHostnameByAddr("127.0.0.1", 27015))
    Call WSACleanup
    End
End Sub

Merci beaucoup c parfais!!!
je mettrais par la suite l ensemble de mon code permettant de creer la liste des ip, tout en ressensant leur hostname, os, et logicielle installé! en repertoriant tout sa dans exel!
sa fais encore pas mal de taf mais bon!

encore une fois merci!