sushinutnc
New Member
- Joined
- Jul 23, 2009
- Messages
- 15
I have some code that will parse the FIRST IP address it finds in a string. Could someone help with the code for continuing through the remaining part of the string and parsing out any additional IP addresses it finds and concatenating them with a comma and space (", ")?
There are specific rules for validating a "proper" IP, but for the purposes of my work, I don't need to validate. I found the following code on a google group (thanks Jeff M). All it does is parse the numeric text surrounding the 3 periods that all valid IPv4 addresses contain. For my purposes, it works.
*******************************
Function FindIP(IP As String) As String
Dim cnt As Integer, NoOfDots As Integer
Dim i As Integer, c As Integer
For i = 1 To Len(IP)
If IsNumeric(Mid(IP, i, 1)) Or Mid(IP, i, 1) = "." Then
cnt = cnt + 1
Else
'More than 6 consecutive char's that are
'either numeric or dot (".")
If cnt > 6 Then
FindIP = Mid(IP, i - cnt, cnt)
'Count the number of dot's
NoOfDots = 0
For c = 1 To Len(FindIP)
If Mid(FindIP, c, 1) = "." Then
NoOfDots = NoOfDots + 1
End If
Next c
'Check no of dots (s/b 3)
If NoOfDots = 3 Then
Exit Function
Else
FindIP = ""
End If
End If
cnt = 0
End If
Next i
End Function
*******************************
So, what I need is for this code to loop through the rest of the input string and pull out any additional IPs (an array?).
Here are two examples (there may be 100s of chars in a input field. These are just examples).
************
EXAMPLE INPUT1:
We have a problem with 192.168.3.43 and also with 172.16.234.12. Also might have a problem with 10.168.4.1.
OUTPUT with above code is:
192.168.3.43
DESIRED OUTPUT:
192.168.3.43, 172.16.234.12, 10.168.4.1
************
************
EXAMPLE INPUT2:
There is a system at 192.168.23.142, but it's not communicating with 192.168.4.132. Please call me at 555.432.2534 to see if it's talking to 10.4.22.3. My IP is 172.16.4.12. Thanks!
OUTPUT with above code is:
192.168.23.142
DESIRED OUTPUT:
192.168.23.142, 192.168.4.132, 10.4.22.3, 172.16.4.12
************
(BTW, I didn't want to get technical with this, but if anyone wants to validate parsed IPs, they are comprised of four, 8-bit numbers (octets) separated by three "dots". For the purposes of this discussion valid IPs could range from "0.0.0.0" to "255.255.255.255"; i.e., each octet can range from 0-255).
THANK you in advance for any help!
There are specific rules for validating a "proper" IP, but for the purposes of my work, I don't need to validate. I found the following code on a google group (thanks Jeff M). All it does is parse the numeric text surrounding the 3 periods that all valid IPv4 addresses contain. For my purposes, it works.
*******************************
Function FindIP(IP As String) As String
Dim cnt As Integer, NoOfDots As Integer
Dim i As Integer, c As Integer
For i = 1 To Len(IP)
If IsNumeric(Mid(IP, i, 1)) Or Mid(IP, i, 1) = "." Then
cnt = cnt + 1
Else
'More than 6 consecutive char's that are
'either numeric or dot (".")
If cnt > 6 Then
FindIP = Mid(IP, i - cnt, cnt)
'Count the number of dot's
NoOfDots = 0
For c = 1 To Len(FindIP)
If Mid(FindIP, c, 1) = "." Then
NoOfDots = NoOfDots + 1
End If
Next c
'Check no of dots (s/b 3)
If NoOfDots = 3 Then
Exit Function
Else
FindIP = ""
End If
End If
cnt = 0
End If
Next i
End Function
*******************************
So, what I need is for this code to loop through the rest of the input string and pull out any additional IPs (an array?).
Here are two examples (there may be 100s of chars in a input field. These are just examples).
************
EXAMPLE INPUT1:
We have a problem with 192.168.3.43 and also with 172.16.234.12. Also might have a problem with 10.168.4.1.
OUTPUT with above code is:
192.168.3.43
DESIRED OUTPUT:
192.168.3.43, 172.16.234.12, 10.168.4.1
************
************
EXAMPLE INPUT2:
There is a system at 192.168.23.142, but it's not communicating with 192.168.4.132. Please call me at 555.432.2534 to see if it's talking to 10.4.22.3. My IP is 172.16.4.12. Thanks!
OUTPUT with above code is:
192.168.23.142
DESIRED OUTPUT:
192.168.23.142, 192.168.4.132, 10.4.22.3, 172.16.4.12
************
(BTW, I didn't want to get technical with this, but if anyone wants to validate parsed IPs, they are comprised of four, 8-bit numbers (octets) separated by three "dots". For the purposes of this discussion valid IPs could range from "0.0.0.0" to "255.255.255.255"; i.e., each octet can range from 0-255).
THANK you in advance for any help!