ASP transforms IP address to long integer number

Source: Internet
Author: User
Sometimes we will display the user's area on the page, the principle is: first get the user's IP, and then go to the query to convert IP to a number, and finally to check the range of the number, come to the user's place.
IP conversion to numeric methods:
Suppose IP is 192.168.0.1
192*255*255*255+168*255*255+0*255+1
The result is the value to be obtained.

Converts an IP address to a long integer

<%
Function Clngip (ByVal asnewip)
Dim Lnresults
Dim Lnindex
Dim lnipary
Lnipary = Split (Asnewip, ".", 4)
For lnindex = 0 to 3
If not Lnindex = 3 Then
Lnipary (Lnindex) = Lnipary (lnindex) * (256 ^ (3-lnindex))
End If
Lnresults = Lnresults + lnipary (lnindex)
Next
CLNGIP = Lnresults
End Function
%>


Inverse function

<%
Function Cstrip (ByVal annewip)
Dim Lsresults
Dim lntemp
Dim Lnindex
For lnindex = 3 to 0 Step-1
Lntemp = Int (Annewip/(256 ^ lnindex))
Lsresults = lsresults & Lntemp & "."
Annewip = Annewip-(lntemp * (256 ^ lnindex))
Next
Lsresults = Left (Lsresults, Len (lsresults)-1)
Cstrip = Lsresults
End Function
%>
-->
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.