'************************************** ' Name: Function to test for a valid IP ' Address ' Description:This function will return ' True if the passed value is a valid IP A ' ddress. I basically made this for my DNS ' Hostname DLL I was working on so that I ' could use just one method. Works REALLY ' fast. ' By: _maniac_ ' ' Inputs:Host As String ' ' Returns:True if the Host is a valid IP ' Address, False if not. '
Public Function IsIPAddress(Host As String) As Boolean
'Quick length test If Len(Host) > 15 Or Len(Host) < 7 Then 'Host is longer or shorter than possible IP IsIPAddress = False Exit Function End If
'Split components between periods Dim tmpParts() As String Dim i As Integer tmpParts = Split(Host, ".")
'Check number of components If UBound(tmpParts) <> 3 Then 'Not correct numbers of periods/components IsIPAddress = False Exit Function Else 'Follows IP format - Check each component For i = 1 To UBound(tmpParts) If IsNumeric(tmpParts(i)) = False Or Len(tmpParts(i)) > 3 Then 'Non-numeric or too long IsIPAddress = False Exit Function Else 'Test value If CInt(tmpParts(i)) > 255 Then 'Value too large IsIPAddress = False Exit Function End If End If Next End If
'Passed all tests IsIPAddress = True End Function
Fandt denne
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.