Guest User

Untitled

a guest
Apr 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. strComputer = "."
  2.  
  3.  
  4.  
  5. Set objWMIService = GetObject("winmgmts:" _
  6.  
  7.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  8.  
  9.  
  10.  
  11. Set colAdapters = objWMIService.ExecQuery _
  12.  
  13.     ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True")
  14.  
  15.  
  16.  
  17.  For Each objAdapter in colAdapters
  18.  
  19.     If Not IsNull(objAdapter.IPAddress) Then
  20.  
  21.       For i = 0 To UBound(objAdapter.IPAddress)
  22.  
  23.          IPAddr = objAdapter.IPAddress(i)
  24.  
  25.       Next
  26.  
  27.    End If
  28.  
  29.  
  30.  
  31.    If Not IsNull(objAdapter.IPSubnet) Then
  32.  
  33.       For i = 0 To UBound(objAdapter.IPSubnet)
  34.  
  35.          SubnetAddr = objAdapter.IPSubnet(i)
  36.  
  37.       Next
  38.  
  39.    End If
  40.  
  41.  Next
  42.  
  43.  
  44.  
  45. dim strIPAddress, strSubnetmask, CStatus, lacienas01, lacieshare01, lacienas02, lacieshare02
  46.  
  47. CStatus = 2
  48.  
  49. strIPAddress = IPAddr
  50.  
  51. strSubnetmask = SubnetAddr
  52.  
  53.  
  54.  
  55. Dim arrNetIDNumIPs
  56.  
  57. arrNetIDNumIPs = CalcNetIDandNumIPs(strIPaddress, strSubnetmask)
  58.  
  59. Dim strNetworkID
  60.  
  61. strNetworkID = arrNetIDNumIPs(0)
  62.  
  63. Dim intNumberofIPs
  64.  
  65. intNumberofIPs = arrNetIDNumIPs(1)
  66.  
  67. Dim strBroadcastIP
  68.  
  69. strBroadcastIP = CalcBroadcastIP(strNetworkID,intNumberofIPs)
  70.  
  71. ' Call function to check if source files are in C: drive
  72.  
  73. '  CStatus = 0 = no           CStatus = 1 = yes
  74.  
  75. Call CheckC(CStatus)
  76.  
  77. WScript.echo CStatus
  78.  
  79. If CStatus = 0 Then
  80.  
  81.     Call PingSubnet(strNetworkID, intNumberofIPs)
  82.  
  83.     Call CopySourceFiles(lacieshare01, lacieshare02)
  84.  
  85. Else ' DO INSTALL AFTER ANOTHER CHECK
  86.  
  87.     WScript.quit(0)
  88.  
  89. End If
  90.  
  91.  
  92.  
  93.  
  94.  
  95. sub PingSubnet(strNetworkID, intNumberofIPs)
  96.  
  97.         Dim strPingIP
  98.  
  99.         strPingIP = IncrementIP(strNetworkID)
  100.  
  101.         Call PingHost(strPingIP)
  102.  
  103.         getArp(strPingIP)
  104.  
  105.         wscript.echo vbcr
  106.  
  107.         Dim i
  108.  
  109.         For i = 1 to (intNumberofIPs - 3)
  110.  
  111.                 strPingIP = IncrementIP(strPingIP)
  112.  
  113.                 Call PingHost(strPingIP)
  114.  
  115.                 GetArp(strPingIP)
  116.  
  117.         Next
  118.  
  119. End Sub
  120.  
  121.  
  122.  
  123. sub PingHost(strPingIP)
  124.  
  125.         Dim WshShell, WshPing, strPingResults
  126.  
  127.         'Wscript.StdOut.Write strPingIP
  128.  
  129.         Set WshShell = WScript.CreateObject("WScript.Shell")
  130.  
  131.         Set WshPing = WshShell.Exec("ping -n 1 -w 100 " & strPingIP) ';send 3 echo requests, waiting 1 sec each
  132.  
  133.         strPingResults = LCase(WshPing.StdOut.ReadAll)
  134.  
  135. end Sub
  136.  
  137.  
  138.  
  139. Function CopySourceFiles(lacieshare01, lacieshare02)
  140.  
  141.     Const OverwriteExisting = True
  142.  
  143.     Set objFSO = CreateObject("Scripting.FileSystemObject")
  144.  
  145.     If objFSO.FolderExists("C:\Office2010\") Then
  146.  
  147.     objFSO.CopyFolder lacieshare02 & "\Office2010" , "C:\" , OverwriteExisting
  148.  
  149.     Else
  150.  
  151.     objFSO.CreateFolder ("C:\Office2010\")
  152.  
  153.     objFSO.CopyFolder lacieshare02 & "\Office2010" , "C:\" , OverwriteExisting
  154.  
  155.     End If
  156.  
  157.     If objFSO.FolderExists("C:\IE8\") Then
  158.  
  159.     objFSO.CopyFolder lacieshare02 & "\IE8" , "C:\" , OverwriteExisting
  160.  
  161.     Else
  162.  
  163.     objFSO.CreateFolder ("C:\IE8\")
  164.  
  165.     objFSO.CopyFolder lacieshare02 & "\IE8" , "C:\" , OverwriteExisting
  166.  
  167.     End If
  168.  
  169. End Function
  170.  
  171.  
  172.  
  173. Function GetArp(strPingIP)
  174.  
  175.         Dim WshShell, WshArp, strArpResult
  176.  
  177.         Set WshShell = WScript.CreateObject("WScript.Shell")
  178.  
  179.         Set WshArp = WshShell.Exec("arp -a " & strPingIP)
  180.  
  181.         strArpResult = WshArp.StdOut.ReadAll
  182.  
  183.         Dim RegEx, Matches, Match
  184.  
  185.         Set RegEx = New RegExp
  186.  
  187.         RegEx.IgnoreCase = True
  188.  
  189.         RegEx.Global = True
  190.  
  191.         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}"
  192.  
  193.         If Regex.Test(strArpResult) = True then
  194.  
  195.           'Wscript.StdOut.Write ", MAC(s)"
  196.  
  197.                 Set Matches = RegEx.Execute(strArpResult)
  198.  
  199.                 For each Match in Matches
  200.  
  201.                         If Match = "00-d0-4b-8d-86-13"  Then
  202.  
  203.                             lacienas01 = strPingIP
  204.  
  205.                             wscript.StdOut.Write lacienas01
  206.  
  207.                             lacieshare01 = "\\" & lacienas01 & "\root"
  208.  
  209.                             'Set objNetwork = CreateObject("WScript.Network")
  210.  
  211.                             'objNetwork.MapNetworkDrive "Z:" , lacieshare01
  212.  
  213.                         ElseIf Match = "00-d0-4b-8d-86-4f" Then
  214.  
  215.                             lacienas02 = strPingIP
  216.  
  217.                             wscript.StdOut.Write lacienas02
  218.  
  219.                             ' Map lacie drive                          
  220.  
  221.                             lacieshare02 = "\\" & lacienas02 & "\Public"
  222.  
  223.                             'Set objNetwork = CreateObject("WScript.Network")
  224.  
  225.                             'objNetwork.MapNetworkDrive "Q:" , lacieshare02                
  226.  
  227.                             'wscript.StdOut.Write " Lacie " & Match
  228.  
  229.                         'if not Match = "00-00-00-00-00-00" Then
  230.  
  231.                          '       wscript.StdOut.Write " " & Match
  232.  
  233.                         End If
  234.  
  235.                 Next
  236.  
  237.         End if
  238.  
  239. End Function
  240.  
  241.  
  242.  
  243.  Function CheckC(CStatus)
  244.  
  245.  ' Check free disk space and quit if under 4.5 GB
  246.  
  247.     Dim filesys
  248.  
  249.     'Set wshShell = WScript.CreateObject( "WScript.Shell" )
  250.  
  251.     'strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
  252.  
  253.     'ComputerNameFail = strComputerName
  254.  
  255.     Set filesys = CreateObject("Scripting.FileSystemObject")
  256.  
  257.     Set objWMIService = GetObject("winmgmts:")
  258.  
  259.     Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
  260.  
  261.    
  262.  
  263.     If filesys.FileExists("c:\Office2010\Office2010_Desktop.MSP") Then
  264.  
  265.         CStatus =  "1"
  266.  
  267.         If objLogicalDisk.FreeSpace < 1610612736 Then
  268.  
  269.             'Set failspacetxt = filesys.OpenTextFile("C:\failspace.txt", ForAppending, True)
  270.  
  271.             'failspacetxt.WriteLine(ComputerNameFail)
  272.  
  273.             WScript.quit(2)
  274.  
  275.         End If
  276.  
  277.     Else
  278.  
  279.         CStatus = "0"  
  280.  
  281.         If objLogicalDisk.FreeSpace < 4831838208 Then
  282.  
  283.             'Set failspacetxt = filesys.OpenTextFile("C:\failspace.txt", ForAppending, True)
  284.  
  285.             'failspacetxt.WriteLine(ComputerNameFail)
  286.  
  287.             WScript.quit(2)
  288.  
  289.         End If
  290.  
  291.     End If
  292.  
  293. End Function
  294.  
  295.  
  296.  
  297. Function CalcLastHostIP(strBroadcastIP)
  298.  
  299.         Dim arrBroadcastIP
  300.  
  301.         arrBroadcastIP = Split(strBroadcastIP,".")
  302.  
  303.         CalcLastHostIP = arrBroadcastIP(0) &"."& arrBroadcastIP(1) &"."&arrBroadcastIP(2) &"."& (arrBroadcastIP(3) - 1)
  304.  
  305. End Function
  306.  
  307.  
  308.  
  309. Function CalcBroadcastIP(strNetworkID,intNumberofIPs)
  310.  
  311.         CalcBroadcastIP = strNetworkID
  312.  
  313.         dim i
  314.  
  315.         For i = 1 to (intNumberofIPs - 1)
  316.  
  317.                 CalcBroadcastIP = IncrementIP(CalcBroadcastIP)
  318.  
  319.         Next
  320.  
  321. End Function
  322.  
  323.  
  324.  
  325. Function CalcNetIDandNumIPs(strIPaddress, strSubnetmask) ';check for proper subnet mask values; calc NetworkID; calc Number of IPs
  326.  
  327. Dim arrReturn(2)
  328.  
  329. Dim arrSubnetmask ';each octet is an element of the array
  330.  
  331. Dim arrIPaddress';each octet is an element of the array
  332.  
  333. arrSubnetmask = Split(strSubnetmask,".")
  334.  
  335. arrIPaddress = Split(strIPaddress,".")
  336.  
  337. Dim arrNetworkIP(3) ';the starting address for the subnet
  338.  
  339. Dim arrBroadcastIP(3) ';the final (ending) address for the subnet
  340.  
  341. Dim intOctet ';counter to determine which of the four octets (0 to 3) we are processing
  342.  
  343. intOctet = 0
  344.  
  345. Dim intNumIPsPerOctet ';number of IPs (or networks) allowed by the octet (a multiplier value)
  346.  
  347. Dim intNumIPs ';number of hosts the mask allows (including broadcast IP & network address IP)
  348.  
  349. intNumIPs = 1
  350.  
  351.  
  352.  
  353. Call SubnetmaskContainsProperValues(strSubnetmask, arrSubnetmask,0) ';test for proper values in subnet mask
  354.  
  355. Do Until intOctet = 4   ';parse each octet separately, check for proper values and calculate NetworkID & Number of IPs
  356.  
  357.         Select Case arrSubnetmask(intOctet)
  358.  
  359.         Case "0"                
  360.  
  361.                 intNumIPsPerOctet = 256 - arrSubnetmask(intOctet)
  362.  
  363.                 Call Subnetmask0FollowedBy0(strSubnetmask, arrSubnetmask, intOctet)
  364.  
  365.                 arrNetworkIP(intOctet) = CalcNetworkID(arrIPAddress(intOctet), intNumIPsPerOctet)
  366.  
  367.         Case "255"
  368.  
  369.                 intNumIPsPerOctet = 256 - arrSubnetmask(intOctet)
  370.  
  371.                 Call Subnetmask255PrecededBy255(strSubnetmask, arrSubnetmask, intOctet)
  372.  
  373.                 arrNetworkIP(intOctet) = CalcNetworkID(arrIPAddress(intOctet), intNumIPsPerOctet)
  374.  
  375.         Case Else
  376.  
  377.                 intNumIPsPerOctet = 256 - arrSubnetmask(intOctet)
  378.  
  379.                 Call SubnetmaskOthervalFollowedBy0s(strSubnetmask, arrSubnetmask, intOctet)
  380.  
  381.                 Call SubnetmaskOthervalPrecededBy255s(strSubnetmask, arrSubnetmask, intOctet)
  382.  
  383.                 arrNetworkIP(intOctet) = CalcNetworkID(arrIPAddress(intOctet), intNumIPsPerOctet)
  384.  
  385.         End Select
  386.  
  387.         intNumIPs = intNumIPs * IntNumIPsPerOctet
  388.  
  389.         intOctet = IntOctet + 1
  390.  
  391. Loop
  392.  
  393. arrReturn(0) = arrNetworkIP(0) &"."& arrNetworkIP(1) &"."& arrNetworkIP(2) &"."& arrNetworkIP(3)
  394.  
  395. arrReturn(1) = intNumIPs
  396.  
  397. CalcNetIDandNumIPs = arrReturn
  398.  
  399. End Function
  400.  
  401.  
  402.  
  403. Function CalcNetworkID(OctetVal, IntNumIPsPerOctet) ';calculate the network ID
  404.  
  405.         Dim intWhichNet
  406.  
  407.         Dim intStartAddress
  408.  
  409.         intWhichNet = OctetVal \ intNumIpsperOctet ';integer result only; we don';t care about the remainder
  410.  
  411.         CalcNetworkID = intWhichNet * IntNumIPsPerOctet
  412.  
  413. End Function
  414.  
  415.  
  416.  
  417. Function IncrementIP(strStartIP)
  418.  
  419. ';takes IP as string, increments it by 1
  420.  
  421.         Dim arrStartIP
  422.  
  423.         arrStartIP = Split(strStartIP,".")
  424.  
  425.                 if arrStartIP(3) < 255 then
  426.  
  427.                         arrStartIP(3) = arrStartIP(3) + 1
  428.  
  429.                 else
  430.  
  431.                         if arrStartIP(2) < 255 then
  432.  
  433.                                 arrStartIP(2) = arrStartIP(2) + 1
  434.  
  435.                                 arrStartIP(3) = 0
  436.  
  437.                         else
  438.  
  439.                                 if arrStartIP(1) < 255 then
  440.  
  441.                                         arrStartIP(1) = arrStartIP(1) + 1
  442.  
  443.                                         arrStartIP(2) = 0
  444.  
  445.                                         arrStartIP(3) = 0
  446.  
  447.                                 else
  448.  
  449.                                         if arrStartIP(0) < 255 then
  450.  
  451.                                                 arrStartIP(0) = arrStartIP(0) + 1
  452.  
  453.                                                 arrStartIP(2) = 0
  454.  
  455.                                                 arrStartIP(2) = 0
  456.  
  457.                                                 arrStartIP(3) = 0
  458.  
  459.                                         else
  460.  
  461.                                                 wscript.echo "Oops, cannot increment past 255.255.255.255 !"
  462.  
  463.                                                 wscript.quit
  464.  
  465.                                         end if
  466.  
  467.                                 end if
  468.  
  469.                         end if
  470.  
  471.                 end if
  472.  
  473.         IncrementIP = arrStartIP(0) &"."& arrStartIP(1) &"."& arrStartIP(2) &"."& arrStartIP(3)
  474.  
  475. End Function
  476.  
  477.  
  478.  
  479. Sub SubnetmaskOthervalFollowedBy0s(strSubnetmask, arrSubnetmask, intOctet)
  480.  
  481. ';all values following octet(iterator) that';s not 255 or 0 must be 0
  482.  
  483.         if intOctet = 3 Then Exit Sub ';don';t perform check on last octet!
  484.  
  485.         Dim iterator
  486.  
  487.         iterator = intOctet + 1
  488.  
  489.         For iterator = intOctet + 1 to Ubound(arrSubnetmask)            
  490.  
  491.                         if arrSubnetmask(iterator) <> 0 Then    
  492.  
  493.                                 Wscript.Echo "Subnet Mask (" &strSubnetmask&  ") octet value {128, 192, 224, 240, 248, 252, 254}  is not followed by all zeros."
  494.  
  495.                                 ExitBadSubnetMask(strSubnetMask)
  496.  
  497.                         end if
  498.  
  499.         Next
  500.  
  501. end sub
  502.  
  503.  
  504.  
  505. Sub SubnetmaskOthervalPrecededBy255s(strSubnetmask, arrSubnetmask, intOctet)
  506.  
  507.         ';all values preceding octet(iterator) that';s not 255 or 0 must be 255
  508.  
  509.         if intOctet = 0 Then Exit Sub ';don';t perform check on first octet!
  510.  
  511.         Dim iterator
  512.  
  513.         iterator = intOctet -1  
  514.  
  515.         For iterator = Lbound(arrSubnetmask) to intOctet - 1
  516.  
  517.                         if arrSubnetmask(iterator) <> 255 Then  
  518.  
  519.                                 Wscript.Echo "Subnet Mask (" &strSubnetmask&  ") octet value {128, 192, 224, 240, 248, 252, 254}  is not preceded by all 255s."
  520.  
  521.                                 ExitBadSubnetMask(strSubnetMask)
  522.  
  523.                         end if
  524.  
  525.         Next
  526.  
  527. end Sub
  528.  
  529.  
  530.  
  531. Sub Subnetmask0FollowedBy0(strSubnetmask, arrSubnetmask, intOctet)
  532.  
  533.         ';octet value 0 must be followed by 0';s
  534.  
  535.         if intOctet = 3 Then Exit Sub ';don';t perform check on last octet!
  536.  
  537.         Dim iterator
  538.  
  539.         iterator = intOctet + 1
  540.  
  541.         For iterator = (intOctet + 1) to Ubound(arrSubnetmask)          
  542.  
  543.                         if arrSubnetmask(iterator) <> 0 Then    
  544.  
  545.                                 Wscript.Echo "Subnet Mask (" &strSubnetmask&  ") octet value 0 is not followed by 0."
  546.  
  547.                                 ExitBadSubnetMask(strSubnetMask)
  548.  
  549.                         end if
  550.  
  551.         Next
  552.  
  553. end sub
  554.  
  555.  
  556.  
  557. Sub Subnetmask255PrecededBy255(strSubnetmask, arrSubnetmask, intOctet)
  558.  
  559.         ';255 must be preceeded by 255s
  560.  
  561.         if intOctet = 0 Then Exit Sub ';don';t perform check on first octet!
  562.  
  563.         Dim iterator
  564.  
  565.         For iterator = intOctet to Lbound(arrSubnetmask) step -1
  566.  
  567.                         if arrSubnetmask(iterator) <> 255 Then  
  568.  
  569.                                 Wscript.Echo "Subnet Mask (" &strSubnetmask&  ") octet value 255 is not preceded by all 255s."
  570.  
  571.                                 ExitBadSubnetMask(strSubnetMask)
  572.  
  573.                         end if
  574.  
  575.         Next
  576.  
  577. end sub
  578.  
  579.  
  580.  
  581. sub SubnetmaskContainsProperValues(strSubnetmask, arrSubnetmask, intOctet)
  582.  
  583.         ';There must be 4 octets
  584.  
  585.         ' replaced ' replaced ' replaced &apos;and each octet must be one of: 0, 128, 192, 224, 240, 248, 252, 254, 255
  586.  
  587.         Dim iterator
  588.  
  589.         Dim arrSubnetProperValues
  590.  
  591.         If Ubound(arrSubnetmask) <> 3 Then
  592.  
  593.                 wscript.Echo "The subnet mask must contain 4 octets; given mask (" &strSubnetmask& ") does not."
  594.  
  595.                 ExitBadSubnetMask(strSubnetmask)
  596.  
  597.         End If
  598.  
  599.         arrSubnetProperValues = Array(0, 128, 192, 224, 240, 248, 252, 254, 255)
  600.  
  601.         Dim FoundAProperValue
  602.  
  603.         FoundAProperValue = False
  604.  
  605.         Dim SubnetProperValuesCounter
  606.  
  607.         For iterator = Lbound(arrSubnetMask) to Ubound(arrSubnetmask)
  608.  
  609.                 For SubnetProperValuesCounter = Lbound(arrSubnetProperValues) to Ubound(arrSubnetProperValues)
  610.  
  611.                         if arrSubnetmask(iterator) = Cstr(arrSubnetProperValues(SubnetProperValuesCounter)) Then FoundAProperValue=True
  612.  
  613.                 Next
  614.  
  615.                 if not FoundAproperValue = True Then
  616.  
  617.                         wscript.Echo "Each subnet mask octet must be one of: 0, 128, 192, 224, 240, 248, 252, 254, 255"
  618.  
  619.                         ExitBadSubnetMask(strSubnetmask)
  620.  
  621.                 End If
  622.  
  623.                 FoundAProperValue=False
  624.  
  625.         Next
  626.  
  627.  
  628.  
  629. end sub
  630.  
  631.  
  632.  
  633. sub ExitBadSubnetMask(strSubnetMask)
  634.  
  635.         Wscript.Echo "Bad subnet mask " & strSubnetmask & " - exiting."
  636.  
  637.         Wscript.Quit
  638.  
  639. End Sub
Add Comment
Please, Sign In to add comment