对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!
Posted fntp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!相关的知识,希望对你有一定的参考价值。
Hello,大家好,我是fntp,本期更新博客,为大家带来最新一期的鑫软教程,带大家一起来学习!现阶段,我们面临着数据信息隐私泄露的风险,怎么各种网络应用服务在我们注册完账号后,不断地给我们发送垃圾信息,那如何避免每天收到这么多垃圾信息,避开信息隐私泄露?我们可以使用Java实现短信接码工具奥!基于网络号码实现接收网络短信,多人共用,解决一时之需!
首先还是老规矩,我们先来看效果实现的怎么样:
工具软件截图如下所示:
实现原理如下:
- 使用Jsoup(Java网络爬虫)爬出html
- 使用字符串解析工具剔除无用字符,取出有效数据
- 使用Java的Table实现数据表格展示
- 使用Java的GUI进行窗口化程序,显得更加美观
好啦,来看一下核心代码实现吧:
package com.sinsy.fntp.utils;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Utils
// ==========基础方法
public Document getDocument (String url)
try
return Jsoup.connect(url).timeout(5000).get();
catch (IOException e)
e.printStackTrace();
return null;
// ==========拿到号码数组
public String[] getPhoneNumbers()
Document doc = new Utils().getDocument("http://www.z-sms.com/");
// 获取目标HTML代码
Elements thefirstElement = doc.select("[class=col-md-4]");
// 拿到目前的所有号码的个数
int count = thefirstElement.size();
int number = 1;
//count就是总的数量,也就可以作为这个数组的总的容量
String phoneNumber[] = new String[count];
String phoneQuhao[] = new String[count];
for(int i = 0;i<count;i++)
Elements elements2 = thefirstElement.select("[class=course]");
String phonenumberZong= elements2.select("[class=number]").get(i).text().replace("复制", ",").replace(" ", ",").replace("+","-");
// 拿到区号
String qh =new Utils().SplitTheJson(phonenumberZong);
// 拿到号码段
String phonenumber =new Utils().SplitTheJson2(phonenumberZong);
// System.out.println(phonenumberZong);
// System.out.println(" 号码为: [ "+number+" ] "+"区号:"+qh+"号码:"+phonenumber);
phoneNumber[i] = phonenumber;
phoneQuhao[i]= qh;
number++;
// System.out.println(count);
return phoneNumber;
// =====================获得区号数组
public String[] getQuhao()
Document doc = new Utils().getDocument("http://www.z-sms.com/");
// 获取目标HTML代码
Elements thefirstElement = doc.select("[class=col-md-4]");
// 拿到目前的所有号码的个数
int count = thefirstElement.size();
int number = 1;
//count就是总的数量,也就可以作为这个数组的总的容量
String phoneQuhao[] = new String[count];
for(int i = 0;i<count;i++)
Elements elements2 = thefirstElement.select("[class=course]");
String phonenumberZong= elements2.select("[class=number]").get(i).text().replace("复制", ",").replace(" ", ",").replace("+","-");
// 拿到区号
String qh =new Utils().SplitTheJson(phonenumberZong);
// System.out.println(phonenumberZong);
// System.out.println(" 号码为: [ "+number+" ] "+"区号:"+qh);
phoneQuhao[i]= qh;
number++;
// System.out.println(count);
return phoneQuhao;
// 刷新时间数组
public String[] getRefreshTime()
Document doc = new Utils().getDocument("http://www.z-sms.com/");
// 获取目标HTML代码
Elements thefirstElement = doc.select("[class=col-md-4]");
// 拿到目前的所有号码的个数
int count = thefirstElement.size();
int number = 1;
//count就是总的数量,也就可以作为这个数组的总的容量
String RefreshTime[] = new String[count];
Elements elements2 = thefirstElement.select("[class=course]");
for(int i = 0;i<count;i++)
String phonenumberZong= elements2.get(i).text().replace(" ", ",");
phonenumberZong= new Utils().SplitTheJson1(phonenumberZong);
// System.out.println(" 号码为: [ "+number+" ] "+"刷新时间:"+phonenumberZong);
RefreshTime[i]= phonenumberZong;
number++;
// System.out.println(count);
return RefreshTime;
// 字符串匹配算法
public String SplitTheJson(String str)
String regex = "-(.*?),";
String param ="";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(str);
while (m.find())
int i = 1;
param+=m.group(i);
i++;
return param;
public String SplitTheJson2(String str)
String regex = ",(.*?),";
String param ="";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(str);
while (m.find())
int i = 1;
param+=m.group(i);
i++;
return param;
public String SplitTheJson1(String str)
String regex = "复制,(.*?),";
String param ="";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(str);
while (m.find())
int i = 1;
param+=m.group(i);
i++;
return param;
// 拿到短信内容的代码:http://www.z-sms.com/lv.php?pho_num=17194242613&1
public String GetContent(String str)
Document doc = new Utils().getDocument("http://www.z-sms.com/lv.php?pho_num="+str+"&1");
// 获取目标HTML代码
Elements thefirstElement = doc.select("[class=conters]");
// 拿到目前的所有号码的个数
//count就是总的数量,也就可以作为这个数组的总的容量
Elements elements2 = thefirstElement.select("span");
// String imgpath = elements2.select("img[src]").get(0).toString().replace("<img alt=\\"(更多号码 www.z-sms.com )\\" src=\\"", "").replace("\\">", "");
String yzm= elements2.get(0).text();
// System.out.println(yzm+"img地址:"+imgpath);
return yzm;
public String GetImagePath(String str)
Document doc = new Utils().getDocument("http://www.z-sms.com/lv.php?pho_num="+str+"&1");
// 获取目标HTML代码
Elements thefirstElement = doc.select("[class=conters]");
// 拿到目前的所有号码的个数
//count就是总的数量,也就可以作为这个数组的总的容量
Elements elements2 = thefirstElement.select("span");
String imgpath = elements2.select("img[src]").get(0).toString().replace("<img alt=\\"(更多号码 www.z-sms.com )\\" src=\\"", "").replace("\\">", "");
return imgpath;
// //这是最近刷新时间的开始
// Elements quhao = thefirstElement.select("[class=col-md-4]");
// String refresh = quhao.select("p").get(1).text();
//最近刷新时间的结束
public static void main(String[] args)
for (int i = 0; i <5; i++)
// System.out.println(new Utils().GetContent(new Utils().getPhoneNumbers()[i]));
获得时间的核心代码:
package com.sinsy.fntp.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
public class GetCurrentDate
public static void main(String[] args)
System.out.println(new GetCurrentDate().GetDate());
public String GetDate()
Date date = new Date();
SimpleDateFormat simple = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
// System.out.println(simple.format(date));
return simple.format(date);
最后窗口化的程序实现代码:
package com.sinsy.fntp.mian;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;
import com.sinsy.fntp.utils.GetCurrentDate;
import com.sinsy.fntp.utils.Utils;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class Mainwindows
protected Shell shlv;
private Table table;
private GetCurrentDate date = new GetCurrentDate();
private Utils utils= new Utils();
/**
* Launch the application.
* @param args
*/
public static void main(String[] args)
try
Mainwindows window = new Mainwindows();
window.open();
catch (Exception e)
e.printStackTrace();
/**
* Open the window.
*/
public void open()
Display display = Display.getDefault();
createContents();
shlv.open();
shlv.layout();
while (!shlv.isDisposed())
if (!display.readAndDispatch())
display.sleep();
/**
* Create contents of the window.
*/
protected void createContents()
Display display = Display.getDefault();
shlv = new Shell(display,SWT.MIN);
shlv.setSize(830, 608);
shlv.setText("\\u946B\\u8F6F\\u624B\\u673A\\u9A8C\\u8BC1\\u7801\\u4EE3\\u6536\\u5DE5\\u5177V1.0");
Composite composite_2 = new Composite(shlv, SWT.BORDER);
composite_2.setBounds(10, 137, 599, 414);
// JavaSWT嵌入Table表单事件
table = new Table(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
table.addSelectionListener(new SelectionAdapter()
@Override
public void widgetSelected(SelectionEvent e)
String url = table.getItem(table.getSelectionIndex()).getText(6);
new showcode().openwindow(url);
);
table.setBounds(0, 0, 595, 410);
table.setHeaderVisible(true);
table.setLinesVisible(true);
String tableHeader[]= new String[] "时间","区号","手机号码","上次刷新","来源";
for (int i=0;i<tableHeader.length;i++)
TableColumn tableColumn = new TableColumn(table, SWT.CENTER);
tableColumn.setText( tableHeader[i]);
//设置表头可移动,默认为false
tableColumn.setMoveable(true);
tableColumn.setWidth(196);
TableColumn tableColumn = new TableColumn(table, SWT.CENTER);
tableColumn.setText("短信内容(默认字符串验证码)");
tableColumn.setMoveable(true);
tableColumn.setWidth(396);
TableColumn tableColumn1 = new TableColumn(table, SWT.CENTER);
tableColumn1.setText("图片验证码");
tableColumn1.setMoveable(true);
tableColumn1.setWidth(396);
Date date = new Date();
SimpleDateFormat simple = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
// System.out.println(simple.format(date));
String qh[]=utils.getQuhao();
String pn[]=utils.getPhoneNumbers();
String tm[]=utils.getRefreshTime();
for (int i = 0; i < 24; i++) 大厂面试题:有了G1还需要其他垃圾回收器吗?我教你怎么答