Home--> Articles -->Site Tools

Convert LongIP to StringIP

Post By 21658 on 2008-9-19 15:16:57  [Reads:289]


Name: Convert LongIP to StringIP
ASP code
Description: This function converts a Long Number (3232235521) into an IP Address ("192.168.0.1"). Why would you want to do this? Click here.
Inputs: anNewIP - IP Address as a Long Number (no dots)

Returns: Returns the string representation of an IP Address ("192.168.0.1")

Function CStrIP(ByVal anNewIP)
Dim lsResults ' Results To be returned
Dim lnTemp ' Temporary #118alue being parsed
Dim lnIndex ' Position of number being parsed
' If pulling number from an Access Database,
' The variable Type "Long" ranges from -2147483648 To 2147483647
' You will first need To add 2147483648 to the number to parse correctly.
' anNewIP = anNewIP + 2147483648
' Parse highest numbers first
For lnIndex = 3 To 0 Step -1

' Parse the current #118alue For this position
lnTemp = Int(anNewIP / (256 ^ lnIndex))

' Append the number To the final results delimited by a dot
lsResults = lsResults & lnTemp & "."

' Remove the number that we just parsed
anNewIP = anNewIP - (lnTemp * (256 ^ lnIndex))

Next

' Cut off last dot
lsResults = Left(lsResults, Len(lsResults) - 1)

' Return the results
CStrIP = lsResults

End Function

Sponsor Sites

Free Articles


Categories