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!

Seperate IP Address (Text Manipulation) 1

Status
Not open for further replies.

ErroR

Technical User
Apr 9, 2001
79
US
I'm trying to build a list of servers that workstations should contact depending on the subnet they are in.

What would be the simplest way to break an IP address down into the first three octets and then compare it against a list of the servers the workstations should contact. Basically, if the workstation is in the 10.1.1.x subnet, it would go to server A and if it is in the 10.2.1.x subnet it would go to server B, etc.

This is sloppy but I just threw it together to show the breakdown of the IP.

Code:
  a = InStr(1, strIPAddress, ".")
  b = InStr((a + 1), strIPAddress, ".")
  c = InStr((b + 1), strIPAddress, ".")
  
  lngOctet01 = Mid(strIPAddress, 1, (a - 1))
  lngoctet02 = Mid(strIPAddress, (a + 1), (b - a))
  lngoctet03 = Mid(strIPAddress, (b + 1), (c - b))
 

Check out the split function...

[tt]
Dim MyArray() As String, I As Integer

MyArray = Split(strIPAddress, ".")

For I = LBound(MyArray) To UBound(MyArray)
Debug.Print MyArray(I)
Next I
[/tt]

Good Luck

 
Well now that was too easy...

Thanks for the hint....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top