线路分流自动智能跳转代码,自动选择最快镜像网站(js)

  JS脚本无数据库代码

  

复制代码 代码如下:

  <Script Langage=Javascript>

  i=1

  var autourl=new Array()

  autourl[1]="http://www.abc.com/default.asp" //修改为网通访问地址

  autourl[2]="http://abc.com/default.asp" //修改为电信访问地址

  function auto(url)

  {

  if(i)

  {

  i=0;

  top.location=url

  }}

  function run()

  {

  for(var i=1;

  i<autourl.length;i++)

  document.write("<img src="+autourl[i]+" width=1 height=1 onerror=auto('"+autourl[i]+"')>")

  }

  run()

  </script>

  JS脚本数据库代码

  

复制代码 代码如下:

  '版权所有

  <%

  On Error Resume next

  dim conn,dbpath,UserIP

  set conn=server.createobject("adodb.connection")

  DBPath = Server.MapPath("IP.mdb")

  conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath

  If Err Then

  err.Clear

  Set Conn = Nothing

  Response.Write "数据库正在更新中,请稍后再试!"'注释,需要把这几个字翻译成英文。

  Response.End

  End If

  myip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

  If myip = "" Then myip = Request.ServerVariables("REMOTE_ADDR")

  tempip=myip

  myip = Split(myip,".")

  if Ubound(myip)=3 then

  For i=0 To Ubound(myip)

  myip(i)=left(myip(i),3)

  if isnumeric(myip(i)) then

  myip(i)=cint(myip(i))

  else

  myip(i)=0

  end if

  next

  myipnumeber=myip(0)*256*256*256+myip(1)*256*256+myip(2)*256+myip(3)

  sql="select addr from ip where ip1<="&myipnumeber&" and ip2>="&myipnumeber

  set rs1=conn.execute(sql)

  if not rs1.eof then

  response.redirect "http://www.***.com" '是网通的话则跳转到网通的网址去,自己修改为自己的网站

  Else

  response.redirect "http://www.****.com" '不是网通的则跳转到的网址,自己修改,不废话了

  end if

  rs1.close

  set rs1=nothing

  conn.close

  set conn=nothing

  end if%>

  如:

  

复制代码 代码如下:

  <html>

  <head>

  <title>标题</title>

  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

  <meta name="keywords" content="keywords">

  <meta name="description" content="description">

  <meta content="Copyright" name="author">

  </head>

  <body>

  <table width="564" height="40%" border="0" align="center">

  <tr>

  <td><div align="center"><span class="style2">尊敬的游客<br>您好!正在为您自动选择最快的线路</span><strong>标题</strong><br>

  <br>

  <span class="style1">速度测试中……</span></div>

  <div style="display:none;">

  </div>

  <div align="center">

  <script>

  i=1

  var autourl=new Array()

  autourl[1]="电信地址" //修改为电信访问地址

  autourl[2]="网通地址" //修改为网通访问地址

  function auto(url)

  {

  if(i)

  {

  i=0;

  top.location=url

  }}

  function run()

  {

  for(var i=1;i<autourl.length;i++)

  document.write("<img src='"+autourl[i]+"' width=1 height=1 onerror=auto('"+autourl[i]+"')>")

  }

  run()

  </script>

  </div></td>

  </tr>

  </table>

  </body>

  </html>

  另一实例:

  

复制代码 代码如下:

  <%

  '-------------------------------------------------------------------------------------------------

  Function GetUserIPInfo '根据当前用户使用线路信息

  Set XMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")

  'XMLHTTP.Open "Get","http://www.dns7.cn/ip/?ip="&GetUserIP(),false

  XMLHTTP.Open "Get","http://www.dns7.cn/ip/?ip=60.12.1.2",false

  XMLHTTP.Send

  strResult= bytes2BSTR(XMLHTTP.ResponseBody)

  GetUserIPInfo=strResult

  End Function

  '-------------------------------------------------------------------------------------------------

  Function RemoteGetIPInfo(IP) '根据用户IP,得到使用线路信息

  Set XMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")

  XMLHTTP.Open "Get","http://www.dns7.cn/ip/?ip="&IP,false

  XMLHTTP.Send

  strResult= bytes2BSTR(XMLHTTP.ResponseBody)

  RemoteGetIPInfo=strResult

  End Function

  '-------------------------------------------------------------------------------------------------

  Function GetUserIP() '得到用户IP地址

  Dim userip,userip2

  userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

  userip2 = Request.ServerVariables("REMOTE_ADDR")

  If userip = "" Then

  GetUserIP=userip2

  Else

  GetUserIP=userip

  End If

  End Function

  '-------------------------------------------------------------------------------------------------

  Function bytes2BSTR(vIn) '内部函数调用

  strReturn = ""

  For i = 1 To LenB(vIn)

  ThisCharCode = AscB(MidB(vIn,i,1))

  If ThisCharCode < &H80 Then

  strReturn = strReturn & Chr(ThisCharCode)

  Else

  NextCharCode = AscB(MidB(vIn,i+1,1))

  strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))

  i = i + 1

  End If

  Next

  bytes2BSTR = strReturn

  End Function

  '-------------------------------------------------------------------------------------------------

  %>

  <%

  'Response.write GetUserIP()

  %>

  <br>

  <%

  Response.write RemoteGetIPInfo("202.108.9.16")

  %>

  <br>

  <%

  Response.write GetUserIPInfo

  %>

  这个可以实现多服务器分流,可以实现线路自动识别跳转,其原理很简单,无论用户进入你哪个服务器只要你在默认页面使用这个代码,他就会跳转到访问速度最快的服务器,这样可以实现服务器分流,适用于流量大的,有多个线路多个服务器的!

  本人经过测试非常好用

  代码一:

  在要跳转的页面上写上:

  Copy code

  

复制代码 代码如下:

  <script language="JavaScript">

  var m=50000;

  var n=Math.floor(Math.random()*m+1)

  //alert(n);

  document.write("<iframe src=http://cnc.glzy8.com/test.htm?"+n+"||"+location.search.replace(/\?/g,"")+" WIDTH=0 HEIGHT=0 MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=0 SCROLLING=NO></iframe>");

  document.write("<iframe src=http://dx.glzy8.com/test.htm?"+n+"||"+location.search.replace(/\?/g,"")+" WIDTH=0 HEIGHT=0 MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=0 SCROLLING=NO></iframe>");

  document.write("<iframe src=http://www.glzy8.com/test.htm?"+n+"||"+location.search.replace(/\?/g,"")+" WIDTH=0 HEIGHT=0 MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=0 SCROLLING=NO></iframe>");

  </script>

  --------------------------------------------------------------------------------------

  然后写test.htm页面代码:注意每个服务器站点(我上面代码分别为网通,电信,铁通)你自己根据自己站点情况修改里面的网址,这里只是演示,上面网址并不存在,在那几个服务器里面都放下面的test.htm) 都要放这个文件:

  Copy code

  

复制代码 代码如下:

  <script language="JavaScript">

  /*

  这里写上一些文字,不要太多150-200行就可以了,主要作用是,如果你的站点默认页面为DEFAULT。HTM你把代码一,放上去后他会检测你所有服务器的test.htm,然后读取test.htm文件,寻找最快的页面,哪个访问速度快就进哪个站点,这里要写上文字,就是为了让他来检测读取速度,也不要太少,太少检测不出速度!

  */

  if (top.location !== self.location) {

  top.location=self.location;

  }

  var url1,url2;

  url1=location.search.replace(/\?/g,"")

  url2=url1.split("||");

  location.href="index.htm";

  </script>