⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipcheck.jsp

📁 陕西电信sp客户端
💻 JSP
字号:
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.security.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%!
    class OnlineUser {
        public String IPAddress;
        public String AccountNO;
        public String CalledNO;
        public String CallingNO;
        public java.util.Date LoginTime;

        public String toString(){
            return "用户记录:IPAddress="+IPAddress+" ,AccountNO="+AccountNO+" ,CalledNO="+CalledNO+" ,CallingNO="+CallingNO+" ,LoginTime="+LoginTime;
        }
    }
    public static String byte2HEX(byte b) {
        return (""+"0123456789ABCDEF".charAt(0xf&b>>4)+"0123456789ABCDEF".charAt(b&0xF));
    }
    public static byte stringHEX2bytes(String str) {
        return (byte) ("0123456789ABCDEF".indexOf(str.substring(0,1))*16 + "0123456789ABCDEF".indexOf(str.substring(1)));
    }
    public static String md5bytes2string(byte[] bytes){
        String result = "";
        for(int i=0; i<bytes.length; i++){
            result += byte2HEX(bytes[i]);
        }
        return result;
    }
    public static byte[] md5string2bytes(String str){
        byte[] b = new byte[str.length()/2];
        for(int i=0; i<b.length; i++){
            String s = str.substring(i*2,i*2+2);
            b[i] = stringHEX2bytes(s);
        }
        return b;
    }
    /**
     * 从response字符串中,取出key字段的值,如果key指定的字段不存在,返回null
     * @param key -- 字段名称
     * @param response -- Time接口返回的内容。
     * @return 字段的值,如果字段不存在返回null.
     */
    public static String getAttribue(String key, String response)
    {
        String POSTFIX = "=\"";
        String RIGTH_PARENTHESIS = "\"";
        String field = key + POSTFIX;
        String result = null;
        if(response == null || response.trim().length() == 0)
        {
            return null;
        }
        if(response.indexOf(field) < 0)
        {
            return null;
        }
        int pre = response.indexOf(field) + field.length();
        int post = response.indexOf(RIGTH_PARENTHESIS, pre);
        if(post < 0)
        {
            return null;
        }
        result = response.substring(pre, post);
        if(result != null && result.trim().length() == 0)
        {
            return null;
        }
        return result;
    }
%>
<%
    String ipaddress = request.getParameter("ipaddress");
    if(ipaddress == null || ipaddress.length()==0){
        //初始页面
%>
<html>
<head>
<title>
检查IP是否在线
</title>
</head>
<body>
<form method="post" name="form1" action="ipcheck.jsp">
检查IP是否在线
IP地址<input name="ipaddress" type="text" value="192.168.0.1">
<input type="submit" >

</form>
</body>
</html>
<%

    }else {

    String ICPCode="test";
    String ICPKey="7EF36F3A638D3066";
    String seed = ICPCode + ICPKey + ipaddress;
    MessageDigest md = MessageDigest.getInstance("MD5");
    String ICPVerifyCode = md5bytes2string(md.digest(seed.getBytes()));

    String serverVerifyURL = "http://192.168.2.156:8080/nas/interface/CheckOnline.jsp";
    serverVerifyURL += "?icpcode=" + ICPCode + "&icpverifycode=" + ICPVerifyCode + "&ipaddress=" + ipaddress ;

    System.out.println(serverVerifyURL);
    //invoke jsp pages here
    URL aurl = new URL(serverVerifyURL);
    BufferedReader in = new BufferedReader(new InputStreamReader(aurl.openStream()));
    String line=null;
    String errormessage=null;
    String result=null;
    String AccountNO=null;
    String CalledNO=null;
    String CallingNO=null;
    String LoginTime=null;
    OnlineUser online = new OnlineUser();
    while((line=in.readLine())!=null){
        System.out.println(line);
        if(line.length()>0 && line.indexOf("Response")!=-1 && line.indexOf("Result")!=-1){
            errormessage=getAttribue("ErrorMessage",line);
            result=getAttribue("Result",line);
            AccountNO =getAttribue("AccountNO",line);
            CalledNO =getAttribue("CalledNO",line);
            CallingNO =getAttribue("CallingNO",line);
            LoginTime =getAttribue("LoginTime",line);
            if("3000".equals(result)||"2000".equals(result)){
                //发现错误或对帐成功
                break;
            }else{
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
                online.IPAddress = ipaddress;
                online.AccountNO = AccountNO;
                online.CalledNO = CalledNO;
                online.CallingNO = CallingNO;
                online.AccountNO = AccountNO;
                online.LoginTime = dateFormat.parse(LoginTime);
            }
        }
    }
    if("3000".equals(result)){
        out.println("发现错误,错误信息为:" + errormessage);
    }else if("1000".equals(result)){
        out.println("该IP在线,详细信息为:" + online);
    }else if("2000".equals(result)){
        out.println("该IP不在线");
    }else{
        out.println("无发失败返回结果");
    }
}

%>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -