问题解决
20151230
ip正则表达式
http://weidongke123-126-com.iteye.com/blog/1976214
java多线程: sdns src/main/java/com/sdns/resolving/action/automaticsaction.action 方法:autoMsd
// 手动 private boolean autoMsd(){ StringBuffer mailnote = new StringBuffer(); // 将 try { StringBuffer ssb = new StringBuffer(); StringBuffer sb = new StringBuffer(); StringBuffer sbrest = new StringBuffer();// 返回的记录集 // 根据Ip 查询 是否有A记录 存在一个风险? 如果 当前的版本 包含的服务器不全面,就不会发布所有的服务器 Version v = versionService.getLastVersion(); RecordsBean rb = new RecordsBean(); rb.setVerid(v.getId()); int rest=0; // 修改 String nip="'"+ip.replace(",","','")+"'"; rest=rest+ recordsInfoService.updateRecordsCurdata(rb, nip, Integer.valueOf(result)); AutoNodeBean autoNodeBean=new AutoNodeBean(); autoNodeBean.setYxstate(Integer.valueOf(result)); autoNodeBean.setHosts(ip); autoNodeBean.setRemark(remark); autoNodeBean.setNode(Integer.valueOf(node)); autoNodeService.updateNodeYxstate(autoNodeBean); // ================= // 修改 切换 if (rest>0) { List<Thread> threadlist=new ArrayList(); // 2012-12-13 v String refs[] = v.getDnsservers().trim().split(","); // String refs[]={"10.200.93.61","10.200.93.62","10.200.93.63","10.200.93.64"}; isqh=1; //username=this.getCurUser().getUsername(); int count =10; for (String rurl : refs) { if (!rurl.equals("")) { // 发布线程 PushThead pt = new PushThead(rurl, v.getId(),userid,isqh,username); //pt.run(); Thread thread2=new Thread(pt,rurl); Thread.sleep(count*2); thread2.start(); ssb = pt.getLog(); // 得到发布日志 sb = pt.getCallBackLog();// 得到服务器返回日志 threadlist.add(thread2); count=count*2; } } for(Thread t:threadlist){ t.join(); } ssb.append("IP ").append(ip).append("[").append(result).append("]").append("[").append(code).append("]"); String nmsg= "DNS切换成功! [切换人:"+this.getUsername()+"," + ip + ",状态:"+result+",代码:"+code+"]" ; ssb.append("<br>").append(nmsg); sendSms( nmsg,wingphones); } else { ssb.append("IP ").append(ip).append("->").append( sbrest.toString()).append("没有对应的节点!"); // sendSms( "automatic:failed![nodeIP:" + ip + ",result:"+result+",code:"+code+",nonodedata]" ); } // 追加 固资中没有提供IP 的列表 this.saveBusiLog(username, "AutomaticSAction", "自动切换", 1, ssb .toString(), "", 0);// mailnote=ssb;// 自动切换 邮件内容 } catch (Throwable e) { e.printStackTrace(); try { // sendSms( "automatic:failed![nodeIP:" + ip + ",result:"+result+",code:"+code+",error]" ); } catch (Throwable ee) { ee.printStackTrace(); } return false; } try { List<RecordsBean> list =null ; sendMail("DNS自动切换提醒",list,1,mailnote.toString(),MailMsgBean.DNSAUTOCMAILTEMPLATE); } catch (Throwable ee) { ee.printStackTrace(); } return true; }
java trim 函数可以
ip 校验正则表达式:
if($("#tagIp").val()!=""){ var re = /^([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/ ; var addresses = $("#tagIp").val().split(","); for(var i=0;i<addresses.length;i++){ if(!re.test(addresses[i])){ window.parent.showMsg("填写的 目标IP ,ip格式不正确,请修改,如有多个ip,请以英文逗号连接!",'2'); setFocus("tagIp"); return false; } } }