zoukankan      html  css  js  c++  java
  • 一段能用来统计ip访问的代码(自用)包括所在地

    <jsp:useBean id="conn1" scope="session" class="china3cts.SnCms" />
    <%
    conn1.Conn();
    //访问IP
    String Ip=request.getRemoteAddr();
    //获取IP来源算法
    String ip1,ip2,ip3,ip4;

     int x=Ip.indexOf(".");
     ip1=Ip.substring(0,x);
     Ip=Ip.substring(x+1,Ip.length());

     x=Ip.indexOf(".");
     ip2=Ip.substring(0,x);
     Ip=Ip.substring(x+1,Ip.length());

     x=Ip.indexOf(".");
     ip3=Ip.substring(0,x);
     ip4=Ip.substring(x+1,Ip.length());

    String Ipone=ip1;
    String Iptwo=ip1+"."+ip2;
    long IpOK;
    IpOK=(long)Integer.valueOf(ip1).intValue()*256*256*256+Integer.valueOf(ip2).intValue()*256*256+Integer.valueOf(ip3).intValue()*256+Integer.valueOf(ip4).intValue();

    String SIp="pp";
    SIp=Long.toString(IpOK);
    String sql="Select Top 1 country,city From sncms_ipaddress Where  ip1<="+SIp+" and ip2>="+SIp+" Order By ip1";
    ResultSet rs=conn1.execute(sql) ;

    String   country="地区不详";
    String   city="地址不详";

    if (rs.next())
    {
    country=rs.getString("country");
    city=rs.getString("city");
    }

    if (city==null)
      city="";

    //统计用IP
    Ip=request.getRemoteAddr();
    //来源
    String Reffer=request.getHeader("Referer");
    String RootPath=request.getRealPath("/") ;
    String URI=request.getRequestURI() ;
    String sPath=request.getQueryString() ;
    //分割操作系统等信息
    String userAgent="";
    userAgent=request.getHeader("User-Agent");

    String Browser = "unknown";
    String os = "unknown";
    //浏览器
    Browser=userAgent.split(";")[1].trim();
    os     =userAgent.split(";")[2].trim();
    userAgent=userAgent.toLowerCase();
    //操作系统
    if (userAgent.indexOf("win") > -1)
    {
     
    if (userAgent.indexOf("windows nt 5.0") > -1 || userAgent.indexOf("winnt5.0") > -1)
    {
      os = "Windows 2000";
    }
    if (userAgent.indexOf("windows nt 5.1") > -1 || userAgent.indexOf("winnt5.1") > -1)
    {
      os = "Windows XP";
    }
    if (userAgent.indexOf("win16") > -1 || userAgent.indexOf("windows 3.") > -1)
    {
      os = "Windows 3.x";
    }
    }
    //统计用代理
    userAgent=request.getHeader("User-Agent");

    //out.print("IP:"+Ip+"<br>");
    //out.print("Reffer:"+Reffer+"<br>");
    //out.print("Browser:"+Browser+"<br>");
    //out.print("Os:"+os+"<br>");
    //out.print("UserAgent:"+userAgent+"<br>");
    //out.print("Country:"+country+"<br>");
    //out.print("City:"+city+"<br>");
    //out.print("RootPath:"+RootPath+"<br>");
    //out.print("URI:"+URI+"<br>");
    //out.print("sPath:"+sPath+"<br>");
    String Uid="test";
    //插入数据库
    String ISQL=null;
    ISQL="insert into SnCms_Logs (Uid,sPat,Pge,ref,Ip,Adr,Bro,Os,Age) values ('"+Uid+"','"+sPath+"','"+URI+"','"+Reffer+"', ";
    ISQL=ISQL+"'"+Ip+"','"+country+city+"','"+Browser+"','"+os+"','"+userAgent+"')";
    conn1.update(ISQL);
    %>

  • 相关阅读:
    OSX安装nginx和rtmp模块(rtmp直播服务器搭建)
    用runtime来重写Coder和deCode方法 归档解档的时候使用
    Homebrew安装卸载
    Cannot create a new pixel buffer adaptor with an asset writer input that has already started writing'
    OSX下面用ffmpeg抓取桌面以及摄像头推流进行直播
    让nginx支持HLS
    iOS 字典转json字符串
    iOS 七牛多张图片上传
    iOS9UICollectionView自定义布局modifying attributes returned by UICollectionViewFlowLayout without copying them
    Xcode6 iOS7模拟器和Xcode7 iOS8模拟器离线下载
  • 原文地址:https://www.cnblogs.com/ddr888/p/528329.html
Copyright © 2011-2022 走看看