strIPV4 = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i = LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
'Filter out IPv6 addresses based on assumption that they will all have a ":" in them.
If Not Instr(IPConfig.IPAddress(i), ":") > 0 Then
strIPV4 = strIPV4 & IPConfig.IPAddress(i)
End If
Next
End If
Next
'Now that we have the IP address, I replace the .'s with 1's, then I take only the last two digits to check for Odd/Even.
CleanNum = Right(Replace(strIPV4,".","1"),2)
'At this point, the number is a text string. We have to make it an integer.
ConvertedIP = FormatNumber(CleanNum,0)
'Then do the math.
If ConvertedIP MOD 2 = 0 Then
'Even number stuff goes here.
WScript.Echo "We take the IP address and replace all the dots with 1's." & VBNewLine _
& "After it's cleaned of dots, we trim it to the last two digits." & VBNewLine _
& "-----------------------------------------------------------" & VBNewLine _
& "IP: " & strIPV4 & VBNewLine _
& "Cleaned and Trimmed: " & CleanNum & VBNewLine _
& "Number is EVEN"
Else
'Odd number stuff goes here.
WScript.Echo "We take the IP address and replace all the dots with 1's." & VBNewLine _
& "After it's cleaned of dots, we trim it to the last two digits." & VBNewLine _
& "-----------------------------------------------------------" & VBNewLine _
& "IP: " & strIPV4 & VBNewLine _
& "Cleaned and Trimmed: " & CleanNum & VBNewLine _
& "Number is ODD"
End If