' ---------------------------------------------------------- ' Script VBS donnant les adresses MAC et IP actives ' des ordinateurs d'un LAN ' ' Syntaxe : ' getip [nom_de_machine] ' nom_de_machine : nom NetBIOS de l'ordinateur à analyser ' si ce nom est omis : ordinateur local ' si ce nom est "/all" : scrutation de tout le réseau ' Exemples : ' getip ' getip springfield ' getip /all ' ' JC BELLAMY © 2002 ' ---------------------------------------------------------- Dim args,ComputerSystem,IPConfigSet, IPConfig, Network,DomainSet,fso,shell Set fso =WScript.CreateObject("Scripting.FileSystemObject") Set network=Wscript.CreateObject("WScript.Network") Set Shell =Wscript.CreateObject("WScript.Shell") Set args=Wscript.Arguments TestHost true local=ucase(network.ComputerName) If args.count=0 then computer=local else computer=ucase(args(0)) If computer="/?" Then mess="Récupération d'adresses MAC et IP" & VBCRLF mess=mess & "JC BELLAMY © 2002" & VBCRLF mess=mess & "-----------------" & VBCRLF mess=mess & "Syntaxe : " & VBCRLF mess=mess & " getip [nom_de_machine]" & VBCRLF mess=mess & " nom_de_machine : nom NetBIOS de l'ordinateur à analyser" & VBCRLF mess=mess & " si ce nom est omis -> ordinateur local" & VBCRLF mess=mess & " si ce nom est ""/all"" -> scrutation de tout le réseau" & VBCRLF mess=mess & " exemples :" & VBCRLF mess=mess & " getip" & VBCRLF mess=mess & " getip springfield" & VBCRLF mess=mess & " getip /all" & VBCRLF wscript.echo mess wscript.quit End If end if Set ComputerSystem = GetObject("winmgmts:{impersonationLevel=impersonate}!//"& Local).InstancesOf ("Win32_ComputerSystem") for each ComputerItem in ComputerSystem domaine=ComputerItem.Domain next If computer="/ALL" Then msgPopup "du domaine",Domaine wscript.echo "--- Exploration du domaine ou workgroup " & Domaine & " ---" set DomainSet=GetObject("WinNT://" & domaine) for each ItemDomain in DomainSet computer=ItemDomain.name If computer<>"Schema" Then GetCfg computer next Else If computer<> local Then msgPopup "de l'ordinateur distant",computer GetCfg computer End If Wscript.quit ' ------------------------------------- Sub GetCfg(computer) wscript.echo "Configuration réseau de l'ordinateur " & computer on error resume next set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & Computer).ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE") If Err.Number<>0 Then wscript.echo " - non accessible -" Else for each IPConfig in IPConfigSet adrIP=IPConfig.IPAddress min=LBound(adrIP) max=UBound(adrIP) nadrIP=max-min+1 adrMAC=IPConfig.MACAddress wscript.echo "* " & IPConfig.Description wscript.echo " adresse MAC : " & adrMAC If nadrIP=1 Then wscript.echo " adresse IP : " & adrIP(min) Else wscript.echo FormatStr(nadrIP,3) & " adresses IP : " & adrIP(min) For i = min+1 To max curadr=adrIP(i) If len(curadr)>0 Then wscript.echo " : " & curadr Next end if wscript.echo " passerelle : " & IPConfig.DefaultIPGateway wscript.echo " masque : " & IPConfig.IPSubnet wscript.echo " DNSHostName : " & IPConfig.DNSHostName DNSsrv=IPConfig.DNSServerSearchOrder min=LBound(DNSsrv) max=UBound(DNSsrv) nDNS=max-min+1 If nDNS=1 Then wscript.echo " serveur DNS : " & DNSsrv(min) Else wscript.echo FormatStr(nDNS,3) & " serveurs DNS : " & DNSsrv(min) For i = min+1 To max curadr=DNSsrv(i) If len(curadr)>0 Then wscript.echo " : " & curadr Next end if next End If on error goto 0 wscript.echo End Sub ' ------------------------------------- Function FormatStr(ch,lmax) l=len(ch) If l"cscript" then If force then Init="Ce script doit être lancé avec CSCRIPT" Else Init="Il est préférable de lancer ce script avec CSCRIPT" End If rep=MsgBox(Init & VBCRLF & _ "Cela peut être rendu permanent avec la commande" & VBCRLF & _ "cscript //H:CScript //S /Nologo" & VBCRLF & _ "Voulez-vous que ce soit fait automatiquement?", _ vbYesNo + vbQuestion,strappli) if rep=vbYes then nomcmd="setscript.bat" Set ficcmd = fso.CreateTextFile(nomcmd) ficcmd.writeline "@echo off" ficcmd.writeline "cscript //H:CScript //S /Nologo" ficcmd.writeline "pause" params="" For i = 0 To nbargs-1 params=params & " " & args(i) next ficcmd.writeline chr(34) & strappli & chr(34) & params ficcmd.writeline "pause" ficcmd.close shell.Run nomcmd, SW_SHOWNORMAL,true force=true end if If force then WScript.Quit end if end sub '-------------------------------------------------------------------- Sub msgPopup(titre,analyse) mess="L'analyse " & titre & " peut prendre un certain temps" & VBCRLF mess=mess & "Veuillez patienter SVP. Merci..." & VBCRLF mess=mess & "(Vous avez 10 s pour arrêter le script en appuyant sur ""Annuler"")" result=shell.Popup(mess, 10, "Analyse " & titre & " " & Analyse, vbOKCancel + vbInformation) If result=vbCancel Then wscript.quit End Sub ' -------------------------------------