转化ip地址为长整型数字的函数

将ip地址转换为长整型

<%
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
%>

逆函数

<%
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
%>

时间: 2024-08-01 19:07:58

转化ip地址为长整型数字的函数的相关文章

ASP转化ip地址为长整型数字

有时候我们会在页面上显示用户的所在地区,这个原理是:先得到用户的IP,然后去查询将IP转换成一个数值,最后去查这个数值所在的范围,来得到用户所在的地方. IP转换成数值的方法: 假设IP是192.168.0.1 192*255*255*255+168*255*255+0*255+1 结果就是要得到的数值. 将ip地址转换为长整型 <%  Function CLngIP(ByVal asNewIP)  Dim lnResults  Dim lnIndex  Dim lnIpAry  lnIpAry

将IP地址转换为长整型、将长整型转换为IP地址

ip地址|转换 将IP地址转换为长整型 Converts a string ip address ("192.168.0.1") to a Long number (3232235521). One of the reasons to do this would be to store IP addresses in databases. Numbers greatly reduce the size required to store this information. Inputs

php实现IP地址转换为整型数字实例

[转换原理]:假设IP为:w.x.y.z,则IP地址转为整型数字的计算公式为:intIP = 256*256*256*w + 256*256*x + 256*y + z [PHP的互转]:PHP的转换方式比较简单,它内置了两个函数 int ip2long ( string $ip_address ) //ip转换成整型数值string long2ip ( string $proper_address ) // 整型数值转换成ip[MySQL的互转]:相对于MsSQL来说MySQL的转换方式比较简

将点分式的IP地址转换成长整型

  /** * */ package test; import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; /** * @author wKF46214 * */ public class IpConvert { /** * @param args */ public static void main(String[] args) { try { long ip1

使用JAVA IP地址转成长整型方法时出现错误

java.lang.NumberFormatException: For input string: "0" 在使用JAVA IP地址转成长整型方法时出现此错误 这里对场景进行记录,以备日后遇到类似的错误,参考如何解决 错误输出: 错误原因:怀疑此处为"\0"字符 解决方法: 作者:csdn博客 微wx笑 更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/

JAVA IP地址转成长整型方法

JAVA IP地址转成长整型方法 代码如下: /** * IP转成整型 * @param ip * @return */ public static Long ip2int(String ip) { Long num = 0L; if (ip == null){ return num; } try{ ip = ip.replaceAll("[^0-9\\.]", ""); //去除字符串前的空字符 String[] ips = ip.split("\\.&

PHP中IP地址与整型数字互相转换详解_php技巧

IP转换成整型存储是数据库优化一大趋势,不少人目前存储IP时还在使用字符串类型存储,字符串索引比整型索引消耗资源很多,特别是表中数据量大的时候,以及求查询某一个ip段的数据,今天说的ip是指ip4,ip6不在本文范围内. 系统函数ip2long与long2ipPHP中有内置函数ip2long可以将ip地址转换整型. 复制代码 代码如下: $ip = '210.110.11.49'; echo ip2long($ip); 输出: 复制代码 代码如下: -764540111 输出的整型有负号是因为我

JAVA中把IP地址转成长整型的方法

代码如下: /** * IP转成整型 * @param ip * @return */ public static Long ip2int(String ip) { Long num = 0L; if (ip == null){ return num; } try{ ip = ip.replaceAll("[^0-9\\.]", ""); //去除字符串前的空字符 String[] ips = ip.split("\\."); if (ips.l

显示ip地址及包含采集功能的全套函数源代码

以下代码包含有显示本机IP地址及远程采集功能的全套通用函数,是一些小偷程序,采集程序的最简单的应用程序包,推荐收藏. 以下是源代码:<% Response.expires = 0 Response.expiresabsolute = now() - 1 Response.addHeader "pragma","no-cache" Response.addHeader "cache-control","private" R