Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to update the virus.vbs file.

Status
Not open for further replies.

Boston2012

Technical User
Nov 8, 2012
17
US
We want to change our current process on how the virus updates are installed on the registers. Below is current vbs file that's being used:

'On Error resume next

Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True[/color]

Dim g_strStore

Set objShell = CreateObject("WScript.Shell")
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
Dim arrTrgClients()
Dim thisComputer

ReDim arrTrgClients(0)

Device = WSHShell.ExpandEnvironmentStrings("%ComputerName%")
thisComputer = Device

strFilePath = "c:\AVDefUpdate\RegisterVirDef.log"
strRetreivalPath="c:\AVDefUpdate"
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open the file for write access.
Set objFile = objFSO.OpenTextFile(strFilePath, _
ForWriting, CreateIfNotExist, OpenAsASCII)

'
' Make sure we're running on a controller.
'

g_strStore = RegExGetBRef(WshNetwork.ComputerName, "^(.+)00$", 1, True)

If (g_strStore = "") Then
objFile.WriteLine "Error: Controller hostname does not match expected pattern (ending with 00)."
WScript.Quit 1
End If

objFile.WriteLine "Starting register copy process"

IPScan()

' ##############################################################################
' POS
' ##############################################################################
For Each strTarget In arrTrgClients

Dev=strTarget


'Copy file
TEMP="cmd /c copy /y c:\AVDefUpdate\currentDef\*.jdb \\" & chr(34) & Dev & "\c$\Documents and Settings\All Users\Application Data\Symantec\Symantec Endpoint Protection\inbox" & chr(34)
objFile.WriteLine TEMP
Set objScriptExec = objShell.Exec(TEMP)
strResponse = objScriptExec.StdOut.ReadAll
objFile.WriteLine strResponse


' ##############################################################################
' write log file
' ##############################################################################
objFile.WriteLine Dev & " Complete"

Next

' Close file.
objFile.Close

' --------- IP Scan Function ---------
Function IPScan()
objFile.WriteLine "Starting IPScan Function"

Dim strPrimaryIP, strMask

strPrimaryIP = ""
strMask = ""

strPrimaryIP = GetPrimaryIP()
If (strPrimaryIP = "") Then
objFile.WriteLine "Error: Could not determine the primary network adapter's IP address."
WScript.Quit 1
End If

strMask = GetMask(strPrimaryIP)
If (strMask = "") Then
objFile.WriteLine "Error: Could not determine the primary network adapter's subnet mask."
WScript.Quit 1
End If

' - Begin Pinging Subnet
objFile.WriteLine "START - Pinging Subnet"

Dim strIP

Dim objSubnet
Set objSubnet = New IPSubnet

objSubnet.Init strPrimaryIP, strMask

strIP = objSubnet.GetNextAddress

Do While (strIP <> "")
Dim strOutput
strOutput = LCase(GetOutput("ping -n 1 -w 100 " & strIP))

If (InStr(strOutput, "reply from") > 0) Then
strOutput = GetOutput("nbtstat -A " & strIP)
Dim strLine
Dim strTemp
Dim blnFoundHost

blnFoundHost = False
strHostName = ""

For Each strLine In Split(strOutput, vbCrLf)
strTemp = RegExGetBRef(strLine, "^\s*([^ <]+)\s*<00>\s*UNIQUE", 1, True)

If (strTemp <> "") Then
Dim strEndChars

strEndChars = RegExGetBRef(strTemp, "^" & g_strStore & "(\d+)$", 1, True)

If (strEndChars <> "00" And strEndChars <> "") Then
' Register
strHostName = strTemp
blnFoundHost = True
Exit For
End If
End If
Next

If (blnFoundHost = True) Then
Index = UBound(arrTrgClients)
arrTrgClients(Index) = strIP
objFile.WriteLine arrTrgClients(Index) & " responded to ping and has register hostname for store '" & g_strStore & "'."
ReDim Preserve arrTrgClients(Index + 1)
End If
End If

strIP = objSubnet.GetNextAddress
Loop

ReDim Preserve arrTrgClients(UBound(arrTrgClients) - 1)
objFile.WriteLine "END - Pinging Subnet"
objFile.WriteLine "Ending IPScan Function"
End Function

' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Function GetPrimaryIP()
Dim strOutput, strLine
Dim strIP

strIP = ""
strOutput = GetOutput("route print")

For Each strLine In Split(strOutput, vbCrLf)
strIP = RegExGetBRef(strLine, "^\s*0\.0\.0\.0\s*0\.0\.0\.0\s*\S+\s+(\S+)", 1, True)
If (strIP <> "") Then Exit For
Next

GetPrimaryIP = strIP
End Function

Function GetMask(strIP)
GetMask = ""

Dim strMask
strMask = ""

On Error Resume Next

Dim objWMI
Set objWMI = GetObject("winmgmts://./root/cimv2")

If (Err.Number) Then
Exit Function
End If

On Error Goto 0

Dim colResults, objResult
Set colResults = objWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True",,48)

Dim i
For Each objResult In colResults
For i = LBound(objResult.IPAddress) To UBound(objResult.IPAddress)
If (objResult.IPAddress(i) = strIP) Then
strMask = objResult.IPSubnet(i)
Exit For
End If
Next

If (strMask <> "") Then Exit For
Next

GetMask = strMask
End Function

Function GetOutput(strCommand)
On Error Resume Next
Dim objFSO, WshShell, objTempFile, strTempFile, strOutput

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")

strTempFile = objFSO.GetTempName
WshShell.Run "%comspec% /c """ & strCommand & " > " & strTempFile & """", 7, True

If (Not objFSO.FileExists(strTempFile)) Then
GetOutput = ""
Else
strOutput = ""
Set objTempFile = objFSO.OpenTextFile(strTempFile, 1)

If (Not Err.Number) Then
Do While (Not objTempFile.AtEndOfStream)
strOutput = strOutput & objTempFile.ReadAll
Loop
objTempFile.Close
End If

GetOutput = strOutput
End If

objFSO.DeleteFile strTempFile, True
Err.Clear
End Function

Function RegExGetBRef(strString, strPattern, intBRef, blnIgnoreCase)
RegExGetBRef = ""

Dim objRegExp
Dim colMatches, objMatch

Set objRegExp = New RegExp

objRegExp.Pattern = strPattern
objRegExp.IgnoreCase = blnIgnoreCase
objRegExp.Global = False
objRegExp.MultiLine = True

Set colMatches = objRegExp.Execute(strString)

For Each objMatch In colMatches
If ((intBRef > 0) And (intBRef <= objMatch.SubMatches.Count)) Then
RegExGetBRef = objMatch.SubMatches(intBRef - 1)
End If
Next
End Function

'
' IPSubnet Class
'

Class IPSubnet
Public m_firstAddress(3)
Public m_lastAddress(3)
Public m_curAddress(3)

Public Sub Init(strIP, strMask)
Dim arrIP, arrMask

m_firstAddress(0) = -1
m_firstAddress(1) = -1
m_firstAddress(2) = -1
m_firstAddress(3) = -1

m_lastAddress(0) = -1
m_lastAddress(1) = -1
m_lastAddress(2) = -1
m_lastAddress(3) = -1

m_curAddress(0) = -1
m_curAddress(1) = -1
m_curAddress(2) = -1
m_curAddress(3) = -1

arrIP = Array(-1,-1,-1,-1)
arrMask = Array(-1,-1,-1,-1)

Dim objRE
Set objRE = New RegExp
objRE.Pattern="^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$"

Dim colMatches, objMatch

Set colMatches = objRE.Execute(strIP)

For Each objMatch In colMatches
arrIP(0) = CInt(objMatch.SubMatches(0))
arrIP(1) = CInt(objMatch.SubMatches(1))
arrIP(2) = CInt(objMatch.SubMatches(2))
arrIP(3) = CInt(objMatch.SubMatches(3))
Next

objRE.Pattern = "^(255|254|252|248|240|224|192|128|0)\.(255|254|252|248|240|224|192|128|0)\." & _
"(255|254|252|248|240|224|192|128|0)\.(255|254|252|248|240|224|192|128|0)$"

Set colMatches = objRE.Execute(strMask)
For Each objMatch In colMatches
arrMask(0) = CInt(objMatch.SubMatches(0))
arrMask(1) = CInt(objMatch.SubMatches(1))
arrMask(2) = CInt(objMatch.SubMatches(2))
arrMask(3) = CInt(objMatch.SubMatches(3))
Next

If (arrMask(0) < 0 Or arrIP(0) < 0) Then Exit Sub

Dim i

For i = 0 To 3
Dim intSubnetSize
intSubnetSize = 256 - arrMask(i)

m_firstAddress(i) = Int(arrIP(i) / intSubnetSize) * intSubnetSize
m_lastAddress(i) = m_firstAddress(i) + intSubnetSize - 1
Next

m_curAddress(0) = m_firstAddress(0)
m_curAddress(1) = m_firstAddress(1)
m_curAddress(2) = m_firstAddress(2)
m_curAddress(3) = m_firstAddress(3)
End Sub

Public Function GetNextAddress()
GetNextAddress = ""

If (m_curAddress(0) < 0 Or m_firstAddress(0) < 0 Or m_lastAddress(0) < 0) Then Exit Function
If (Join(m_curAddress, ".") = Join(m_lastAddress, ".")) Then Exit Function

m_curAddress(3) = m_curAddress(3) + 1

If (m_curAddress(3) > 255) Then
m_curAddress(2) = m_curAddress(2) + (m_curAddress(3) \ 256)
m_curAddress(3) = m_curAddress(3) Mod 256

If (m_curAddress(2) > 255) Then
m_curAddress(1) = m_curAddress(1) + (m_curAddress(2) \ 256)
m_curAddress(2) = m_curAddress(2) Mod 256

If (m_curAddress(1) > 255) Then
m_curAddress(0) = m_curAddress(0) + (m_curAddress(1) \ 256)
m_curAddress(1) = m_curAddress(1) Mod 256
End If

If (m_curAddress(0) > 255) Then
m_curAddress(0) = -1
Exit Function
End If
End If
End If

If (Join(m_curAddress, ".") = Join(m_lastAddress, ".")) Then Exit Function

GetNextAddress = Join(m_curAddress, ".")
End Function
End Class


Here is what I need to incorporate into the above script, can anyone assist?


' Issue SFTP connectivity test to all Registers.
Call WriteToLog("Performing SFTP connectivity test to all detected Registers.")
Call WriteToLog("Killing any existing SFTP processes before proceeding.")
intResult = KillProcess("sftpg3.exe")
Call WriteToLog("Waiting for Registers to finish SFTP test.")
Set objSFTP = TestSFTP(g_objRegister)
intResult = KillProcess("sftpg3.exe")
Call WriteToLog("SFTP tests complete, proceeding.")

' Issue SSH connectivity test to all Registers.
Call WriteToLog("Performing SSH connectivity test to all detected Registers.")
Call WriteToLog("Killing any existing SSH processes before proceeding.")
intResult = KillProcess("sshg3.exe")
Call WriteToLog("Waiting for Registers to finish SSH test.")
Set objSSH = TestSSH(g_objRegister)
intResult = KillProcess("sshg3.exe")
Call WriteToLog("SSH tests complete, proceeding.")

' Report the SFTP/SSH test results.
Call WriteToLog("Register SFTP/SSH test results:")
For Each strRegister in objSFTP
Call WriteToLog("SFTP test for Register" & Chr(32) & strRegister & Chr(32) & "(" & g_objRegister.Item(strRegister) & ")" & Chr(32) &_
"evaluated as" & Chr(32) & objSFTP.Item(strRegister) & ".")
Call WriteToLog("SSH test for Register" & Chr(32) & strRegister & Chr(32) & "(" & g_objRegister.Item(strRegister) & ")" & Chr(32) &_
"evaluated as" & Chr(32) & objSSH.Item(strRegister) & ".")
Next

' Deliver the data.
Call WriteToLog("Delivering files to the Registers.")
Set objData = DeliverFiles(g_objRegister, objSFTP)
Call WriteToLog("Register file delivery results:")
intSuccess = 0
For Each strRegister in objData
Call WriteToLog("File delivery for Register" & Chr(32) & strRegister & Chr(32) & "(" & g_objRegister.Item(strRegister) & ")" & Chr(32) &_
"evaluated as" & Chr(32) & objData.Item(strRegister) & ".")
If objData.Item(strRegister) = "True" Then
Call UpdateCSV(g_objRegister.Item(strRegister), "True", "False")
intSuccess = intSuccess + 1
End If
Next
 
Here is what I need to incorporate into the above script, can anyone assist?

I'm not sure what your question is... you don't know where to put it? Does that last snippet even work?
 
No not sure where to put it. Yes the last snippet does work in another script were using for password rotation and just want to incorporate into this one. Thanks for responding on this.
 
1) At what point do you want the code snippet to execute, in relation to the top script? before? after? at some point during?

2) I notice that several functions in your snippet at the bottom are not defined, so you would also need to bring those into this script to truly "incorporate" it.
WriteToLog, KillProcess, TestSFTP, TestSSH, DeliverFiles, UpdateCSV
 
1) at some point during.

2) Those several functions that are not defined I'm working on those.
 
Can you have it execute after

IPScan() near top of script.

 
Then simply paste it there!

Code:
...
IPScan()

[highlight #FCE94F][b]Paste code snippet here[/b][/highlight] 

' ##############################################################################
 ' POS
 ' ##############################################################################
 For Each strTarget In arrTrgClients
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top