集查询IP地址信息、查询手机号码信息、查询身份证号信息的一个小程序
生活随笔
收集整理的這篇文章主要介紹了
集查询IP地址信息、查询手机号码信息、查询身份证号信息的一个小程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
主界面框架:
package KnowAll;import java.awt.FlowLayout; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea;public class KnowAllPanel extends JFrame{public KnowAllPanel() {showPanel();}JButton findIP = new JButton(" 查 詢 I P ");JButton findMyIP = new JButton("查詢自己的IP地址");JButton findID = new JButton("查詢身份證號");JButton findNUMBER = new JButton("查詢手機號碼");JTextArea myIP = new JTextArea(2, 25);public void showPanel() {this.setTitle("百事通");this.setSize(410, 450);// 左長右高this.setLocation(500, 70);// 左水平又豎直this.setResizable(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);this.setLayout(new FlowLayout(FlowLayout.CENTER));//流式布局//添加圖標并設置尺寸int width = 100;int height = 100;ImageIcon findIdNumber_img = new ImageIcon("img\\idcard.jpg");Image findIdNumber = findIdNumber_img.getImage();findIdNumber = findIdNumber.getScaledInstance(width, height, Image.SCALE_DEFAULT);findIdNumber_img.setImage(findIdNumber);JLabel id = new JLabel(findIdNumber_img,JLabel.CENTER);id.setSize(width, height);ImageIcon findIp_img = new ImageIcon("img\\ip.jpg");Image findIp = findIp_img.getImage();findIp = findIp.getScaledInstance(width, height, Image.SCALE_DEFAULT);findIp_img.setImage(findIp);JLabel ip = new JLabel(findIp_img,JLabel.CENTER);ip.setSize(width, height);ImageIcon findPhoneNumber_img = new ImageIcon("img\\phonenumber.jpg");Image findNumber = findPhoneNumber_img.getImage();findNumber = findNumber.getScaledInstance(width, height, Image.SCALE_DEFAULT);findPhoneNumber_img.setImage(findNumber);JLabel phoneNumber = new JLabel(findPhoneNumber_img,JLabel.CENTER);phoneNumber.setSize(width, height);//將圖標、按鈕添加到面板JPanel jp1 = new JPanel();jp1.add(ip);this.add(jp1);JPanel jp2 = new JPanel();jp2.add(id);this.add(jp2);JPanel jp3 = new JPanel();jp3.add(phoneNumber);this.add(jp3);JPanel jp4 = new JPanel();jp4.add(findIP);jp4.add(findID);jp4.add(findNUMBER);JPanel jp5 = new JPanel();jp5.add(findMyIP);this.add(jp4);this.add(jp5);JPanel jp6 = new JPanel();myIP.setEditable(false);jp6.add(myIP);this.add(jp6);//按鈕添加監聽findIP.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubsetVisible(false);FindipPanel panel = new FindipPanel();dispose();}});findID.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubsetVisible(false);FindidPanel panel = new FindidPanel();dispose();}});findNUMBER.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubsetVisible(false);FindPhoneNumberPanel panel = new FindPhoneNumberPanel();dispose();}});findMyIP.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubmyIP.setText("");myIP.setText(InquireIpFunction.getMyIpFromContent());}});}public static void main(String[] args) {KnowAllPanel panel = new KnowAllPanel();} }查詢身份證號信息框架:
package KnowAll;import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField;public class FindidPanel extends JFrame{public FindidPanel() {// TODO Auto-generated constructor stubshowPanel();}JTextField inputId = new JTextField(20);JButton inquire = new JButton("查詢");JButton back = new JButton("返回");JTextArea resultText = new JTextArea(20, 30);public void showPanel() {this.setTitle("查詢身份證號");this.setSize(410, 450);// 左長右高this.setLocation(500, 70);// 左水平又豎直this.setResizable(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);this.setLayout(new FlowLayout(FlowLayout.CENTER));//流式布局this.add(inputId);this.add(inquire);this.add(back);resultText.setEditable(false);this.add(resultText);back.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubsetVisible(false);KnowAllPanel panel = new KnowAllPanel();dispose();}});inquire.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubString idNumber = inputId.getText();String result = InquireIpFunction.getIdCardInfoFromURL(idNumber);resultText.setText(result);}});}public static void main(String[] args) {FindidPanel panel = new FindidPanel();} }查詢IP地址信息框架:
package KnowAll;import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Scanner;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField;public class FindipPanel extends JFrame {public FindipPanel() {// TODO Auto-generated constructor stubshowPanel();}JTextField inputIp = new JTextField(10);JButton inquire = new JButton("查詢");JButton back = new JButton("返回");JTextArea resultText = new JTextArea(20, 30);public void showPanel() {this.setTitle("查詢IP");this.setSize(410, 450);// 左長右高this.setLocation(500, 70);// 左水平又豎直this.setResizable(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);this.setLayout(new FlowLayout(FlowLayout.CENTER));// 流式布局this.add(inputIp);this.add(inquire);this.add(back);resultText.setEditable(false);this.add(resultText);back.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubsetVisible(false);KnowAllPanel panel = new KnowAllPanel();dispose();}});inquire.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String ip = inputIp.getText();String result = InquireIpFunction.getIpInfoFromURL(ip);resultText.setText(result);}});}public static void main(String[] args) {FindipPanel panel = new FindipPanel();} }查找手機號碼信息框架:
package KnowAll;import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField;public class FindPhoneNumberPanel extends JFrame {public FindPhoneNumberPanel() {// TODO Auto-generated constructor stubshowPanel();}JTextField inputPhoneNumber = new JTextField(10);JButton inquire = new JButton("查詢");JButton back = new JButton("返回");JTextArea resultText = new JTextArea(20, 30);public void showPanel() {this.setTitle("查詢手機號碼");this.setSize(410, 450);// 左長右高this.setLocation(500, 70);// 左水平又豎直this.setResizable(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);this.setLayout(new FlowLayout(FlowLayout.CENTER));// 流式布局this.add(inputPhoneNumber);this.add(inquire);this.add(back);resultText.setEditable(false);this.add(resultText);back.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubsetVisible(false);KnowAllPanel panel = new KnowAllPanel();dispose();}});inquire.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubString phoneNumber = inputPhoneNumber.getText();String result = InquireIpFunction.getPhoneNumberInfoFromURL(phoneNumber);resultText.setText(result);}});}public static void main(String[] args) {FindPhoneNumberPanel panel = new FindPhoneNumberPanel();} }查詢功能實現類:
package KnowAll;import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Scanner;import org.jsoup.Jsoup; import org.jsoup.nodes.Element; import org.jsoup.select.Elements;public class InquireIpFunction {//查詢自己的IPpublic static String getContentFromIp138() {try {URL url = new URL("http://2019.ip138.com/ic.asp");URLConnection conn = url.openConnection();conn.addRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36");Scanner scan = new Scanner(conn.getInputStream());StringBuffer sb = new StringBuffer();while(scan.hasNextLine()) {sb.append(scan.nextLine()).append("\r\n");}return sb.toString();} catch (MalformedURLException e1) {e1.printStackTrace();} catch (IOException e1) {e1.printStackTrace();}return null;}public static String getMyIpFromContent() {int Index = getContentFromIp138().indexOf("<center>");int endIndex = getContentFromIp138().indexOf("</center>");String result = getContentFromIp138().substring(Index+8, endIndex);return result;}//查詢輸入的IP地址的地理位置public static String getIpInfoFromURL(String ip) {StringBuffer content = new StringBuffer();try {Elements es = Jsoup.connect("http://ip138.com/ips138.asp?ip="+ip+"&action=2").get().getElementsByTag("li");if(es.size()>0) {for (int i = 0; i < es.size(); i++) {Element e = es.get(i);content.append(e.text()).append("\r\n");}}else {content.append("IP地址有誤");}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}String result = content.toString();return result;}//查詢身份證號碼信息public static String getIdCardInfoFromURL(String idNumber) {StringBuffer content = new StringBuffer();try {Elements es = Jsoup.connect("http://qq.ip138.com/idsearch/index.asp?userid="+idNumber+"&action=idcard").get().getElementsByTag("td");if(es.size()>0) {for (int i = 0; i < es.size(); i++) {Element e = es.get(i);content.append(e.text()).append("\r\n");}}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}String result = content.toString();return result;}//查詢手機號碼信息public static String getPhoneNumberInfoFromURL(String phoneNumber) {StringBuffer content = new StringBuffer();try {Elements es = Jsoup.connect("http://www.ip138.com:8080/search.asp?mobile="+phoneNumber+"&action=mobile").get().select(".TDC");if(es.size()>0) {for (int i = 3; i < es.size(); i++) {Element e = es.get(i);content.append(e.text()).append("\r\n");}}} catch (IOException e) {e.printStackTrace();}String result = content.toString().replace("測吉兇(新)", "").replace("更詳細的..","");return result;} }?
總結
以上是生活随笔為你收集整理的集查询IP地址信息、查询手机号码信息、查询身份证号信息的一个小程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何给页面加能够临时会话的QQ
- 下一篇: 建议阅读的投资经典55本