[VBSCRIPT]Obtenir des info sur un PC distant
Ma question à une plage de réponse possible BIEN BIEN large, mais bon c'est pas grave je vais essayer de la réduire au maximum.
Tout d'abord le script de base qui fonctionne
Code:
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
| option explicit
dim fso, ipdebut, ipencours, ipfin, PING, PINGIT, MyFile
dim ipd1 ,ipd2, ipd3 ,ipd4 , ipf1, ipf2, ipf3, ipf4
dim WshShell
const ForAppending = 8
const FichierLOG= ""
const NbTestPing = 4
dim ipnumfin, ipnumencours
ipd1=cbyte(inputbox("ipdebut octet1: "))
ipd2=cbyte(inputbox("ipdebut octet2: "))
ipd3=cbyte(inputbox("ipdebut octet3: "))
ipd4=cbyte(inputbox("ipdebut octet4: "))
if ipd4 > 254 OR ipd3 > 254 OR ipd4 = 0 OR ipd3 = 0 then
if ipd4 = 0 OR ipd3 = 0 then
wscript.echo " Un octet ne doit pas etre egale a 0 " & vbcrlf & _
" Le programme va quitter "
else
wscript.echo " Un octet ne doit pas depasser 254 " & vbcrlf & _
" Le programme va quitter "
end if
ipdebut=ipd1 & "." & ipd2 & "." & ipd3 & "." & ipd4
ipencours=ipdebut
Msgbox "IP NON VALIDE = " & ipencours
WScript.Quit
end if
ipdebut=ipd1 & "." & ipd2 & "." & ipd3 & "." & ipd4
Msgbox "Debut de la plage ip = " & ipdebut
ipencours=ipdebut
ipf1=cbyte(inputbox("ipfin octet1: "))
ipf2=cbyte(inputbox("ipfin octet2: "))
ipf3=cbyte(inputbox("ipfin octet3: "))
ipf4=cbyte(inputbox("ipfin octet4: "))
if ipf4 > 254 OR ipf3 > 254 OR ipf4 = 0 OR ipf3 = 0 then
if ipf4 = 0 OR ipf3 = 0 then
wscript.echo " Un octet ne doit pas etre egale a 0 " & vbcrlf & _
" Le programme va quitter "
else
wscript.echo " Un octet ne doit pas depasser 254 " & vbcrlf & _
" Le programme va quitter "
end if
ipfin = ipf1 & "." & ipf2 & "." & ipf3 & "." & ipf4
Msgbox "IP NON VALIDE = " & ipfin
WScript.Quit
end if
ipfin = ipf1 & "." & ipf2 & "." & ipf3 & "." & ipf4
Msgbox "Fin de la plage ip = " & ipfin
ipnumfin=ipf1*16^6 + ipf2*16^4 + ipf3*16^2 + ipf4
pinglogcreate()
do
call pingexe
if PING = 0 then
pinglogwrite()
else
call pingexebis
end if
ipd4 = ipd4 + 1
ipencours=ipd1 & "." & ipd2 & "." & ipd3 & "." & ipd4
ipnumencours=ipd1*16^6 + ipd2*16^4 + ipd3*16^2 + ipd4
if ipd4 = 254 then
ipd3 = ipd3 + 1
ipd4 = 0
end if
loop until ipnumencours > ipnumfin 'cStr(ipencours) > cStr(ipfin)
wscript.echo "c fini"
pinglogclose()
'01 - creation de l'objet
sub creer_objet_fso()
Set fso = CreateObject("Scripting.FileSystemObject")
end sub
'02 - procedure création du fichier log+ecriture de la plage
sub pinglogcreate()
creer_objet_fso()
Set MyFile = fso.CreateTextFile("noterping.txt", ForAppending, True)
' MyFile.WriteLine()
end Sub
'03 - Fonction ping
function pingexe
set WshShell = CreateObject ("Wscript.shell")
PINGIT="cmd /c ping " & ipencours & " -n " & NbTestPing
PING = WshShell.Run(PINGIT,1,TRUE)
End Function
'03bis - Fonction ping2
function pingexebis
set WshShell = CreateObject ("Wscript.shell")
PINGIT="cmd /c ping " & ipencours & " -n 1"
PING = WshShell.Run(PINGIT,1,TRUE)
End Function
'04 - ECRIRE les ping qui ont rép positiv
sub pinglogwrite()
MyFile.WriteLine(ipencours)
end sub
'05 - FERMER le FICHIER LOG
sub pinglogclose()
MyFile.Close
end Sub |
La jusqu'à présent, l'utilisateur tape une tranche d'adresse IP, qui vont être pingées (ca se conjugue en francais? même âs sur que sa existe le verbe pinger ou pinguer 8O !!), puis on écrit dans un fichier UNIQUEMENT les adresse qui réponde à la requête. Bon!!
CA c'est fait!!!
Mon problème, c'est que je n'arrive pas à savoir si l'adresse que je ping est DHCP ou non et pourtant j'ai zoné dans les tréfonds des basfonds de la MSDN de microsoft (qui est tres bien fourni c'est vrai) ou j'ai trouvé l'info suivante
To obtain information for the operating system on a remote computer, use the NetWkstaGetInfo function, the Win32_OperatingSystem WMI class, or the OperatingSystem property of the IADsComputer interface.
Et je dois aussi récupérer l'OS de la machine que je ping, récupérer l'OS d'un PC en local j'ai déjà fait, mais pour les PC distant la.. c'est une autre pair de manche!!