zoukankan      html  css  js  c++  java
  • IP计算

    Now that we've got the database, we will move on to writing the ASP code.

    Firstly, we must know how to get the IP Address of the Visitor. To do that, our code will be

    <%
    strIP = Request.ServerVariables("HTTP_REMOTE_ADDR")
    %>

    The ServerVariables collection contains the combination of values that represent the HTTP headers sent from the visitor's browser to our server. By passing the "HTTP_REMOTE_ADDR" parameter to it, we request the IP Address of the visitor.
    Through this, we will get an IP Address in the format xxx.xxx.xxx.xxx which may look like 108.89.128.147
    But since our database have IP Numbers instead of IP Addresses, we will have to convert the IP Address into an IP Number.
    To convert an IP Address into an IP Number, the formula is
    A * (256*256*256) + B * (256*256) + C * 256 + D
    for the IP Address A.B.C.D
    So, for ease of things, we can use the following function to get an IP Number of an IP Address.

    <%
    Private Function ipAd2ipNum(ipA)
    strO = ipA
    pos1 = InStr(strO, ".")
    intA = CInt(Left(strO, (pos1-1)))
    strO2 = Mid(strO, pos1+1, len(strO))
    pos2 = InStr(strO2, ".")
    intB = CInt(Left(strO2, (pos2-1)))
    strO3 = Mid(strO2, pos2+1, len(strO2))
    pos3 = InStr(strO3, ".")
    intC = CInt(Left(strO3, (pos3-1)))
    intD = CInt(Mid(strO3, pos3+1, len(strO3)))

    intConvert = (intA*(256*256*256)) + (intB*(256*256)) + (intC*256) + intD
    ipAd2ipNum = Trim(intConvert)
    End Function
    %>


    so, we can use this function as

    <%
    strIP = Request.ServerVariables("HTTP_REMOTE_ADDR")
    strIPN = ipAd2ipNum(strIP)
    %>

    Thus we will get the IP Number of our IP Address. Now we are ready to query our ip2country database.
  • 相关阅读:
    numpy.clip(a, a_min, a_max, out=None)(values < a_min are replaced with a_min, and those > a_max with a_max.)
    pytorch使用过程中遇到的一些问题
    conda管理包
    python argparse模块
    pytorch中设定使用指定的GPU
    Linux下dpkg的用法
    python pdb模块
    ubuntu SSH 连接、远程上传下载文件
    Linux中执行shell脚本命令的4种方法总结
    python linux安装anaconda
  • 原文地址:https://www.cnblogs.com/Silver/p/170141.html
Copyright © 2011-2022 走看看