ASP实现IP地址分段计算

ip地址|ip地址

<script language="JScript" Runat="Server">
  function IPDeCode(EIP){
  var Ip1,Ip2,Ip3,Ip4;
  Ip1 = moveByteR(EIP & 0xff000000,3);
  Ip2 = moveByteR(EIP & 0x00ff0000,2);
  Ip3 = moveByteR(EIP & 0x0000ff00,1);
  Ip4 = EIP & 0x000000ff;
  return Ip1 + "." + Ip2 + "." + Ip3 + "." + Ip4;
  }
  
  function moveByteL(num,bytenum){
  return num <<= (bytenum*8)
  }
  function moveByteR(num,bytenum){
  return num >>>= (bytenum*8)
  }
  </script>
  
  在VBs中没有位操作,这样在一个页面中用到了js和vbs,并不好,如果用vbs也可以,不过罗嗦了一些,而且有一点注意,如果在vbs中split("202.102.29.6","."),会得到202,102,29三个数,得不到最后一个6,所以需要将ip换成split("202.102.29.6" & ".",".")
  我用vbs做的,由于没有位操作,所以做得比较麻烦
  <%
  function ip2int(ipstr)
  dim iptemp,max
  iptemp = split(ipstr&".",".")
  max = ubound(iptemp)
  if max <> 4 then
  exit function
  end if
  dim a,b,i
  a = "&H"
  for i = 0 to 3
  b = Hex(iptemp(i))
  if len(b) = 1 then
  b = "0"&b
  end if
  a = a&b
  next
  ip2int = CLng(a)
  end function
  function int2ip(ip)
  dim iptemp,a,ipstr,i,length
  iptemp = Hex(ip)
  length = 8 - len(iptemp)
  for i = 1 to length
  iptemp = "0" & iptemp
  next
  a = left(iptemp,2)
  a = "&H" & a
  i = CInt(a)
  a = CStr(i)
  ipstr = a & "."
  a = mid(iptemp,3,2)
  a = "&H" & a
  i = CInt(a)
  a = CStr(i)
  ipstr = ipstr & a & "."
  a = mid(iptemp,5,2)
  a = "&H" & a
  i = CInt(a)
  a = CStr(i)
  ipstr = ipstr & a & "."
  a = right(iptemp,2)
  a = "&H" & a
  i = CInt(a)
  a = CStr(i)
  ipstr = ipstr & a
  int2ip = ipstr
  end function
  dim testIP,testInt
  testIP="202.102.29.6"
  testInt = ip2int(testIP)
  response.write testIP & " will be encoded to <font color=red>" & testInt & "</font><br>"
  response.write testIP & " will be dencoded to <font color=red>" & int2ip(testInt) & "</font><br>"
  %>

时间: 2024-11-01 11:30:09

ASP实现IP地址分段计算的相关文章

asp下IP地址分段计算函数_应用技巧

IP地址分段计算 <script language="JScript" Runat="Server"> function IPDeCode(EIP){ var Ip1,Ip2,Ip3,Ip4; Ip1 = moveByteR(EIP & 0xff000000,3); Ip2 = moveByteR(EIP & 0x00ff0000,2); Ip3 = moveByteR(EIP & 0x0000ff00,1); Ip4 = EIP

asp下IP地址分段计算函数

IP地址分段计算 <script language="JScript" Runat="Server"> function IPDeCode(EIP){ var Ip1,Ip2,Ip3,Ip4; Ip1 = moveByteR(EIP & 0xff000000,3); Ip2 = moveByteR(EIP & 0x00ff0000,2); Ip3 = moveByteR(EIP & 0x0000ff00,1); Ip4 = EIP

ASP ,IP地址分段计算

ip地址 <script language="JScript" Runat="Server"> function IPDeCode(EIP){ var Ip1,Ip2,Ip3,Ip4; Ip1 = moveByteR(EIP & 0xff000000,3); Ip2 = moveByteR(EIP & 0x00ff0000,2); Ip3 = moveByteR(EIP & 0x0000ff00,1); Ip4 = EIP &am

IP地址分段计算

ip地址 /* written by Jaron ,2000-01-10 *//* 原出处:江都资讯网 http://www.jiangdu.net *//* 转载请注明出处和保留此版权信息 *//* 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net *//*相关文章:http://www.csdn.net/Develop/read_article.asp?id=19652*/<script language="JScript"

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

asp 根据IP地址自动判断转向分站的代码_应用技巧

Function getIpvalue(clientIP)'得到客户端的IP转换成长整型,返回值getIpvalue On Error Resume Next Dim strIp, array_Ip strIp=0 array_Ip = Split(clientIP,".") If UBound(array_Ip)<>3 Then getIpvalue=0 Exit Function End If For i=0 To 3 strIp=strIp+(CInt(array_I

asp 根据IP地址自动判断转向分站的代码

Function getIpvalue(clientIP)'得到客户端的IP转换成长整型,返回值getIpvalue On Error Resume Next Dim strIp, array_Ip strIp=0 array_Ip = Split(clientIP,".") If UBound(array_Ip)<>3 Then getIpvalue=0 Exit Function End If For i=0 To 3 strIp=strIp+(CInt(array_I

asp实现检查ip地址是否为内网或者私有ip地址的代码分享_应用技巧

asp检查ip地址是否为私有/内网ip地址源代码. 内网/私有IP地址网段如下,还有127开头的回环地址: 10.0.0.0-10.255.255.255 172.16.0.0-172.31.255.255 192.168.0.0-192.168.255.255 实现代码: <% function IpToNumber(ip)'IP地址转为数字 arr=split(ip,".") IpToNumber=256*256*256*clng(arr(0))+256*256*clng(a

ASP取得客户端IP地址函数

ASP取得访问者真实IP地址函数  Private Function getIP()  Dim strIPAddr  If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Or InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then   strIPAddr = Reque