Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set colAdapters = objWMIService.ExecQuery _
- ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True")
- For Each objAdapter in colAdapters
- If Not IsNull(objAdapter.IPAddress) Then
- For i = 0 To UBound(objAdapter.IPAddress)
- IPAddr = objAdapter.IPAddress(i)
- Next
- End If
- If Not IsNull(objAdapter.IPSubnet) Then
- For i = 0 To UBound(objAdapter.IPSubnet)
- SubnetAddr = objAdapter.IPSubnet(i)
- Next
- End If
- Next
- dim strIPAddress, strSubnetmask, CStatus, lacienas01, lacieshare01, lacienas02, lacieshare02
- CStatus = 2
- strIPAddress = IPAddr
- strSubnetmask = SubnetAddr
- Dim arrNetIDNumIPs
- arrNetIDNumIPs = CalcNetIDandNumIPs(strIPaddress, strSubnetmask)
- Dim strNetworkID
- strNetworkID = arrNetIDNumIPs(0)
- Dim intNumberofIPs
- intNumberofIPs = arrNetIDNumIPs(1)
- Dim strBroadcastIP
- strBroadcastIP = CalcBroadcastIP(strNetworkID,intNumberofIPs)
- ' Call function to check if source files are in C: drive
- ' CStatus = 0 = no CStatus = 1 = yes
- Call CheckC(CStatus)
- WScript.echo CStatus
- If CStatus = 0 Then
- Call PingSubnet(strNetworkID, intNumberofIPs)
- Call CopySourceFiles(lacieshare01, lacieshare02)
- Else ' DO INSTALL AFTER ANOTHER CHECK
- WScript.quit(0)
- End If
- sub PingSubnet(strNetworkID, intNumberofIPs)
- Dim strPingIP
- strPingIP = IncrementIP(strNetworkID)
- Call PingHost(strPingIP)
- getArp(strPingIP)
- wscript.echo vbcr
- Dim i
- For i = 1 to (intNumberofIPs - 3)
- strPingIP = IncrementIP(strPingIP)
- Call PingHost(strPingIP)
- GetArp(strPingIP)
- Next
- End Sub
- sub PingHost(strPingIP)
- Dim WshShell, WshPing, strPingResults
- 'Wscript.StdOut.Write strPingIP
- Set WshShell = WScript.CreateObject("WScript.Shell")
- Set WshPing = WshShell.Exec("ping -n 1 -w 100 " & strPingIP) ';send 3 echo requests, waiting 1 sec each
- strPingResults = LCase(WshPing.StdOut.ReadAll)
- end Sub
- Function CopySourceFiles(lacieshare01, lacieshare02)
- Const OverwriteExisting = True
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- If objFSO.FolderExists("C:\Office2010\") Then
- objFSO.CopyFolder lacieshare02 & "\Office2010" , "C:\" , OverwriteExisting
- Else
- objFSO.CreateFolder ("C:\Office2010\")
- objFSO.CopyFolder lacieshare02 & "\Office2010" , "C:\" , OverwriteExisting
- End If
- If objFSO.FolderExists("C:\IE8\") Then
- objFSO.CopyFolder lacieshare02 & "\IE8" , "C:\" , OverwriteExisting
- Else
- objFSO.CreateFolder ("C:\IE8\")
- objFSO.CopyFolder lacieshare02 & "\IE8" , "C:\" , OverwriteExisting
- End If
- End Function
- Function GetArp(strPingIP)
- Dim WshShell, WshArp, strArpResult
- Set WshShell = WScript.CreateObject("WScript.Shell")
- Set WshArp = WshShell.Exec("arp -a " & strPingIP)
- strArpResult = WshArp.StdOut.ReadAll
- Dim RegEx, Matches, Match
- Set RegEx = New RegExp
- RegEx.IgnoreCase = True
- RegEx.Global = True
- RegEx.Pattern = "[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}"
- If Regex.Test(strArpResult) = True then
- 'Wscript.StdOut.Write ", MAC(s)"
- Set Matches = RegEx.Execute(strArpResult)
- For each Match in Matches
- If Match = "00-d0-4b-8d-86-13" Then
- lacienas01 = strPingIP
- wscript.StdOut.Write lacienas01
- lacieshare01 = "\\" & lacienas01 & "\root"
- 'Set objNetwork = CreateObject("WScript.Network")
- 'objNetwork.MapNetworkDrive "Z:" , lacieshare01
- ElseIf Match = "00-d0-4b-8d-86-4f" Then
- lacienas02 = strPingIP
- wscript.StdOut.Write lacienas02
- ' Map lacie drive
- lacieshare02 = "\\" & lacienas02 & "\Public"
- 'Set objNetwork = CreateObject("WScript.Network")
- 'objNetwork.MapNetworkDrive "Q:" , lacieshare02
- 'wscript.StdOut.Write " Lacie " & Match
- 'if not Match = "00-00-00-00-00-00" Then
- ' wscript.StdOut.Write " " & Match
- End If
- Next
- End if
- End Function
- Function CheckC(CStatus)
- ' Check free disk space and quit if under 4.5 GB
- Dim filesys
- 'Set wshShell = WScript.CreateObject( "WScript.Shell" )
- 'strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
- 'ComputerNameFail = strComputerName
- Set filesys = CreateObject("Scripting.FileSystemObject")
- Set objWMIService = GetObject("winmgmts:")
- Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
- If filesys.FileExists("c:\Office2010\Office2010_Desktop.MSP") Then
- CStatus = "1"
- If objLogicalDisk.FreeSpace < 1610612736 Then
- 'Set failspacetxt = filesys.OpenTextFile("C:\failspace.txt", ForAppending, True)
- 'failspacetxt.WriteLine(ComputerNameFail)
- WScript.quit(2)
- End If
- Else
- CStatus = "0"
- If objLogicalDisk.FreeSpace < 4831838208 Then
- 'Set failspacetxt = filesys.OpenTextFile("C:\failspace.txt", ForAppending, True)
- 'failspacetxt.WriteLine(ComputerNameFail)
- WScript.quit(2)
- End If
- End If
- End Function
- Function CalcLastHostIP(strBroadcastIP)
- Dim arrBroadcastIP
- arrBroadcastIP = Split(strBroadcastIP,".")
- CalcLastHostIP = arrBroadcastIP(0) &"."& arrBroadcastIP(1) &"."&arrBroadcastIP(2) &"."& (arrBroadcastIP(3) - 1)
- End Function
- Function CalcBroadcastIP(strNetworkID,intNumberofIPs)
- CalcBroadcastIP = strNetworkID
- dim i
- For i = 1 to (intNumberofIPs - 1)
- CalcBroadcastIP = IncrementIP(CalcBroadcastIP)
- Next
- End Function
- Function CalcNetIDandNumIPs(strIPaddress, strSubnetmask) ';check for proper subnet mask values; calc NetworkID; calc Number of IPs
- Dim arrReturn(2)
- Dim arrSubnetmask ';each octet is an element of the array
- Dim arrIPaddress';each octet is an element of the array
- arrSubnetmask = Split(strSubnetmask,".")
- arrIPaddress = Split(strIPaddress,".")
- Dim arrNetworkIP(3) ';the starting address for the subnet
- Dim arrBroadcastIP(3) ';the final (ending) address for the subnet
- Dim intOctet ';counter to determine which of the four octets (0 to 3) we are processing
- intOctet = 0
- Dim intNumIPsPerOctet ';number of IPs (or networks) allowed by the octet (a multiplier value)
- Dim intNumIPs ';number of hosts the mask allows (including broadcast IP & network address IP)
- intNumIPs = 1
- Call SubnetmaskContainsProperValues(strSubnetmask, arrSubnetmask,0) ';test for proper values in subnet mask
- Do Until intOctet = 4 ';parse each octet separately, check for proper values and calculate NetworkID & Number of IPs
- Select Case arrSubnetmask(intOctet)
- Case "0"
- intNumIPsPerOctet = 256 - arrSubnetmask(intOctet)
- Call Subnetmask0FollowedBy0(strSubnetmask, arrSubnetmask, intOctet)
- arrNetworkIP(intOctet) = CalcNetworkID(arrIPAddress(intOctet), intNumIPsPerOctet)
- Case "255"
- intNumIPsPerOctet = 256 - arrSubnetmask(intOctet)
- Call Subnetmask255PrecededBy255(strSubnetmask, arrSubnetmask, intOctet)
- arrNetworkIP(intOctet) = CalcNetworkID(arrIPAddress(intOctet), intNumIPsPerOctet)
- Case Else
- intNumIPsPerOctet = 256 - arrSubnetmask(intOctet)
- Call SubnetmaskOthervalFollowedBy0s(strSubnetmask, arrSubnetmask, intOctet)
- Call SubnetmaskOthervalPrecededBy255s(strSubnetmask, arrSubnetmask, intOctet)
- arrNetworkIP(intOctet) = CalcNetworkID(arrIPAddress(intOctet), intNumIPsPerOctet)
- End Select
- intNumIPs = intNumIPs * IntNumIPsPerOctet
- intOctet = IntOctet + 1
- Loop
- arrReturn(0) = arrNetworkIP(0) &"."& arrNetworkIP(1) &"."& arrNetworkIP(2) &"."& arrNetworkIP(3)
- arrReturn(1) = intNumIPs
- CalcNetIDandNumIPs = arrReturn
- End Function
- Function CalcNetworkID(OctetVal, IntNumIPsPerOctet) ';calculate the network ID
- Dim intWhichNet
- Dim intStartAddress
- intWhichNet = OctetVal \ intNumIpsperOctet ';integer result only; we don';t care about the remainder
- CalcNetworkID = intWhichNet * IntNumIPsPerOctet
- End Function
- Function IncrementIP(strStartIP)
- ';takes IP as string, increments it by 1
- Dim arrStartIP
- arrStartIP = Split(strStartIP,".")
- if arrStartIP(3) < 255 then
- arrStartIP(3) = arrStartIP(3) + 1
- else
- if arrStartIP(2) < 255 then
- arrStartIP(2) = arrStartIP(2) + 1
- arrStartIP(3) = 0
- else
- if arrStartIP(1) < 255 then
- arrStartIP(1) = arrStartIP(1) + 1
- arrStartIP(2) = 0
- arrStartIP(3) = 0
- else
- if arrStartIP(0) < 255 then
- arrStartIP(0) = arrStartIP(0) + 1
- arrStartIP(2) = 0
- arrStartIP(2) = 0
- arrStartIP(3) = 0
- else
- wscript.echo "Oops, cannot increment past 255.255.255.255 !"
- wscript.quit
- end if
- end if
- end if
- end if
- IncrementIP = arrStartIP(0) &"."& arrStartIP(1) &"."& arrStartIP(2) &"."& arrStartIP(3)
- End Function
- Sub SubnetmaskOthervalFollowedBy0s(strSubnetmask, arrSubnetmask, intOctet)
- ';all values following octet(iterator) that';s not 255 or 0 must be 0
- if intOctet = 3 Then Exit Sub ';don';t perform check on last octet!
- Dim iterator
- iterator = intOctet + 1
- For iterator = intOctet + 1 to Ubound(arrSubnetmask)
- if arrSubnetmask(iterator) <> 0 Then
- Wscript.Echo "Subnet Mask (" &strSubnetmask& ") octet value {128, 192, 224, 240, 248, 252, 254} is not followed by all zeros."
- ExitBadSubnetMask(strSubnetMask)
- end if
- Next
- end sub
- Sub SubnetmaskOthervalPrecededBy255s(strSubnetmask, arrSubnetmask, intOctet)
- ';all values preceding octet(iterator) that';s not 255 or 0 must be 255
- if intOctet = 0 Then Exit Sub ';don';t perform check on first octet!
- Dim iterator
- iterator = intOctet -1
- For iterator = Lbound(arrSubnetmask) to intOctet - 1
- if arrSubnetmask(iterator) <> 255 Then
- Wscript.Echo "Subnet Mask (" &strSubnetmask& ") octet value {128, 192, 224, 240, 248, 252, 254} is not preceded by all 255s."
- ExitBadSubnetMask(strSubnetMask)
- end if
- Next
- end Sub
- Sub Subnetmask0FollowedBy0(strSubnetmask, arrSubnetmask, intOctet)
- ';octet value 0 must be followed by 0';s
- if intOctet = 3 Then Exit Sub ';don';t perform check on last octet!
- Dim iterator
- iterator = intOctet + 1
- For iterator = (intOctet + 1) to Ubound(arrSubnetmask)
- if arrSubnetmask(iterator) <> 0 Then
- Wscript.Echo "Subnet Mask (" &strSubnetmask& ") octet value 0 is not followed by 0."
- ExitBadSubnetMask(strSubnetMask)
- end if
- Next
- end sub
- Sub Subnetmask255PrecededBy255(strSubnetmask, arrSubnetmask, intOctet)
- ';255 must be preceeded by 255s
- if intOctet = 0 Then Exit Sub ';don';t perform check on first octet!
- Dim iterator
- For iterator = intOctet to Lbound(arrSubnetmask) step -1
- if arrSubnetmask(iterator) <> 255 Then
- Wscript.Echo "Subnet Mask (" &strSubnetmask& ") octet value 255 is not preceded by all 255s."
- ExitBadSubnetMask(strSubnetMask)
- end if
- Next
- end sub
- sub SubnetmaskContainsProperValues(strSubnetmask, arrSubnetmask, intOctet)
- ';There must be 4 octets
- ' replaced ' replaced ' replaced 'and each octet must be one of: 0, 128, 192, 224, 240, 248, 252, 254, 255
- Dim iterator
- Dim arrSubnetProperValues
- If Ubound(arrSubnetmask) <> 3 Then
- wscript.Echo "The subnet mask must contain 4 octets; given mask (" &strSubnetmask& ") does not."
- ExitBadSubnetMask(strSubnetmask)
- End If
- arrSubnetProperValues = Array(0, 128, 192, 224, 240, 248, 252, 254, 255)
- Dim FoundAProperValue
- FoundAProperValue = False
- Dim SubnetProperValuesCounter
- For iterator = Lbound(arrSubnetMask) to Ubound(arrSubnetmask)
- For SubnetProperValuesCounter = Lbound(arrSubnetProperValues) to Ubound(arrSubnetProperValues)
- if arrSubnetmask(iterator) = Cstr(arrSubnetProperValues(SubnetProperValuesCounter)) Then FoundAProperValue=True
- Next
- if not FoundAproperValue = True Then
- wscript.Echo "Each subnet mask octet must be one of: 0, 128, 192, 224, 240, 248, 252, 254, 255"
- ExitBadSubnetMask(strSubnetmask)
- End If
- FoundAProperValue=False
- Next
- end sub
- sub ExitBadSubnetMask(strSubnetMask)
- Wscript.Echo "Bad subnet mask " & strSubnetmask & " - exiting."
- Wscript.Quit
- End Sub
Add Comment
Please, Sign In to add comment