dbWriter IP to number ASP code
Find the long number from an IP.
<%
Function IPToNumber(IPaddress)
DIM i, pos, PrevPos, num
If IPaddress = "" Then
IPToNumber = "error"
Else
For i = 1 To 4
pos = InStr(PrevPos + 1, IPaddress, ".", 1)
If i = 4 Then
pos = Len(IPaddress) + 1
End If
on error resume next
IF NOT isnumeric(Mid(IPaddress, PrevPos + 1, pos - PrevPos - 1))
THEN
IPToNumber = "error"
exit function
end if
num = Int(Mid(IPaddress, PrevPos + 1, pos - PrevPos - 1))
IF num >255 or num="" THEN
IPToNumber = "error"
exit function
END IF
PrevPos = pos
IPToNumber = ((num Mod 256) * (256 ^ (4 - i))) + IPToNumber
Next
End If
End Function
'======= un-comment next line to test
'response.write IPToNumber("26.39.143.55")
%>
|
|