'======================================================================================================== '======================================================================================================== ' ### Script: ip.vbs ' ### Revision: 1 ' ### Created: 04/08/03 ' ### Modified: 04/08/03 ' ### Contact: tim@blackpondfarm.com ' ### Description: gets the IP config from a remote server '======================================================================================================== '======================================================================================================== Option Explicit On error resume next 'Declare variables Dim WshShell,wshFile,objArgs Dim strServer Set WshShell = Wscript.CreateObject("Wscript.shell") Set Wshfile = Wscript.CreateObject("Scripting.FileSystemObject") Set objArgs = WScript.Arguments strServer = objArgs(0) if left(strServer,2) = "\\" then strServer = mid(strServer,3) IF strServer = "" THEN strServer = WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") call ServerData(strServer) '======================================================================================================== '======================================================================================================== Private SUB serverdata(strServer) On error resume next Dim strCmdLine,temp Dim wshtempfile,Line Dim objNetwork,INST,a,i,m,q,names Dim objAdapter Dim objEvents wscript.echo "Servername: " & strServer strCmdLine = "cmd /c ""ping " & strServer & " -n 1 -w 254|findstr /c:Reply > " & strServer & ".txt""" temp = wshshell.Run(strcmdline, 0, true) IF (Wshfile.fileexists(strServer & ".txt")) then Set wshtempfile = wshfile.OpenTextFile(strServer & ".txt", 1) line = wshtempFile.ReadLine IF InStr(10,line,"Destination",1) Then wscript.echo "Unable to connect to " & strServer wscript.quit ELSE END IF wshtempfile.Close wscript.DisconnectObject wshtempfile Set wshtempfile=nothing Wshfile.deletefile(strServer & ".txt") ELSE wscript.echo "Unable to find IP Address for " & strServer wscript.quit END IF 'Testing methods to determine whether the adapter is enabled or disabled... 'Set ObjAdapter = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer).INSTancesOf("Win32_NetworkAdapter") 'IF err = 0 THEN 'For each INST in ObjAdapter ' wscript.echo INST.Availability ' wscript.echo INST.Caption ' wscript.echo INST.StatusInfo 'NEXT 'END IF 'wscript.sleep 3000 Set ObjNetwork = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer).INSTancesOf("Win32_NetworkAdapterConfiguration") IF err = 0 THEN For each INST in ObjNetwork For a = LBound(INST.IPAddress) to UBound(INST.IPAddress) IF INST.IPEnabled(a) = "True" THEN WScript.Echo "IP Address: " & INST.IPAddress(a) WScript.Echo "Subnet Mask: " & INST.IPSubnet(a) WScript.Echo "Default Gateway: " & INST.DefaultIPGateway(a) WScript.Echo "Primary WINS: " & INST.WINSPrimaryServer WScript.Echo "Secondary WINS: " & INST.WINSSecondaryServer WScript.Echo "Physical Address: " & INST.MACAddress wscript.echo "Caption: " & INST.Caption(a) wscript.echo "Description: " & INST.Description(a) wscript.echo "Index: " & INST.Index(a) wscript.echo "ServiceName: " & INST.ServiceName(a) wscript.echo "SettingID: " & INST.SettingID(a) wscript.echo "Metric: " & INST.Metric(a) IF INST.DHCPEnabled(a) = CINT(-1) THEN wscript.echo "DHCP Enabled: Yes" ELSE wscript.echo "DHCP Enabled: No" END IF IF INST.IPXEnabled(a) = "True" Then wscript.echo "IPX Enabled" wscript.echo END IF Next names = "" For q = LBound(INST.DNSServerSearchOrder) to UBound(INST.DNSServerSearchOrder) names = names & " " & INST.DNSServerSearchOrder(q) next IF LEN(names) > 5 THEN WScript.echo "DNS Nameservers:" & names wscript.echo END IF Next ELSE wscript.echo "Unable to access data on " & strServer END IF END SUB '======================================================================================================== '======================================================================================================== Private SUB SCRIPTHELP() WScript.Echo WScript.Echo wscript.echo "ip.vbs" WScript.Echo "Version 1.0" WScript.Echo "=====================================================" Wscript.Echo "Collect basic IPConfig from remote machine" wscript.echo "Assume local machine IF no computer name is provided." WScript.Echo "=====================================================" Wscript.Echo WScript.Echo Wscript.Quit END SUB '======================================================================================================== '======================================================================================================== Private Function blnErrorOccurred (ByVal strIn) IF Err.Number THEN Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & ": " & strIn) IF Err.Description <> "" THEN Call Wscript.Echo( "Error description: " & Err.Description) END IF Err.Clear blnErrorOccurred = True Else blnErrorOccurred = False END IF END Function '======================================================================================================== 'END OF SCRIPT '========================================================================================================