Using VB Script to display part of an IP address
A: Since IP addresses are not fixed length, you will have to count the number of separators before you can extract the octets. With that said, listed below is the sample VB Script code.
strIP = inputbox("Enter an IP Address for testing to extract the first 3 Octets:")
intLastDecimal = 1
For intCounter = 1 to 3
intLastDecimal = InStr(intLastDecimal, strIP, ".") + 1
iNewLength = intLastDecimal-2
strNewIP = Left(strIP, iNewLength )
MsgBox "strNewIP=" & strNewIP
To run this code, simply copy and paste it into a flat file and name it with a .VBS extension.
For more resources on VB Scripting, please visit the following links: