• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 723
  • Last Modified:

I need a script that checks if the IP of the system is 192.X.X.X

I need to modify this part of the script

 With item

      For Each strIPAddress In .IPAddress
                mess = mess & "   " & strIPAddress & VbCrLf
      Next

If the IP for the NIC on the desktop is 192.X.X.X  the script is going to go ahead and do the rest of the code of the script.
If the the IP is not a 192.X.X.X the script is going to stop and exit.
 
Const ForWriting = 2
Dim strComputer
Dim objWMIService
Dim colItems
Set objNetwork = CreateObject("Wscript.Network")

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strName = objNetwork.UserName
strDomain = objNetwork.UserDomain
strPC = objNetwork.ComputerName
'strIP = GetRow("IP Address", objNetwork.IPAddress)
strUser = strDomain & "\" & strName
strText = strUser & vbCrLf

Set wmiService = GetObject("winmgmts:\\" & ComputerName)
Set wmiItems = wmiService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each item In wmiItems
 
   With item

      For Each strIPAddress In .IPAddress
                mess = mess & "   " & strIPAddress & VbCrLf
      Next
   end with
next

Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

For Each objPrinter in colPrinters
    If Not objPrinter.Attributes And 64 Then
        strText = strText & objPrinter.Name & vbCrLf
    End If
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = "C:\temp"
strFullName = objFSO.BuildPath(strPath, strDomain &"-"& strName &"-"& StrPC & ".txt")
Set objFile = objFSO.CreateTextFile(strFullName, ForWriting, True)

objFile.Write strPC & vbCrLf
objFile.Write mess & vbCrLf
objFile.Write strText


objFile.Close
0
llarava
Asked:
llarava
2 Solutions
 
chandru_solCommented:
You can try for the IP address as

If left(strIPAddress,3) = "192" then
"you script goes here"
End if
wscript.quit
0
 
RobSampsonCommented:
Chandru is right, you can use the InStr function to check for the 192:

For Each item In wmiItems
 
   With item

      For Each strIPAddress In .IPAddress
                mess = mess & "   " & strIPAddress & VbCrLf
      Next
   end with
next

If InStr(mess, "192.") > 0 Then
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

For Each objPrinter in colPrinters
    If Not objPrinter.Attributes And 64 Then
        strText = strText & objPrinter.Name & vbCrLf
    End If
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = "\\josuef\temp"
strFullName = objFSO.BuildPath(strPath, strDomain &"-"& strName &"-"& StrPC & ".txt")
Set objFile = objFSO.CreateTextFile(strFullName, ForWriting, True)

objFile.Write strPC & vbCrLf
objFile.Write mess & vbCrLf
objFile.Write strText


objFile.Close
Else
   WScript.Echo "This script will not be run."
End If

Regards,

Rob.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now