/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package phone; import com.mysql.jdbc.Connection; import com.mysql.jdbc.PreparedStatement; import org.apache.http.client.ResponseHandler; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.DefaultHttpClient; /** * * @author Administrator */ public class JavaApp { /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { //获取连接 HttpClient httpclient = new DefaultHttpClient(); ResponseHandler<String> responseHandler = new BasicResponseHandler(); //String ok=""; //三大运营商每年都有新号段根据情况添加号段 String[] haoduan = {"130", "131", "132", "133", "134", "135", "136", "137", "138", "153", "155", "156", "189", "139", "150", "151", "152", "157","185","186", "145", "180", "158", "159", "182", "183", "187", "188", "147"}; for (String x : haoduan) { //System.out.println(x); for (int i = 0; i < 10000; i++) { int k = Integer.parseInt(x) * 10000; k = k + i; // System.out.println(k); HttpGet httpget = new HttpGet("http://haoma.imobile.com.cn/index.php?mob=" + k); //HttpGet httpget = new HttpGet("http://www.ip138.com:8080/search.asp?action=mobile&mobile="+k); String responseBody = httpclient.execute(httpget, responseHandler); //System.out.println(responseBody); //JSONObject json = JSON.parseObject(responseBody); if (responseBody.indexOf("上海") > 0) { //修改你想获取地区号码 // ok=ok+"|"+k; System.out.println(k + "【上海】-" + YunYingShang(x));//修改你想获取地区号码 //ps = (PreparedStatement) conn.prepareStatement("insert into allnumber(number,Callerloc,tmobile) values (?,?,?)"); } } } } public static String YunYingShang(String s) { switch (s) { default: case "130": return "联通"; case "131": return "联通"; case "132": return "联通"; case "155": return "联通"; case "156": return "联通"; case "186": return "联通"; case "145": return "联通"; case "185": return "联通"; case "134": return "移动"; case "135": return "移动"; case "136": return "移动"; case "137": return "移动"; case "138": return "移动"; case "139": return "移动"; case "150": return "移动"; case "151": return "移动"; case "152": return "移动"; case "157": return "移动"; case "158": return "移动"; case "159": return "移动"; case "182": return "移动"; case "183": return "移动"; case "187": return "移动"; case "188": return "移动"; case "147": return "移动"; case "180": return "电信"; case "181": return "电信"; case "133": return "电信"; case "153": return "电信"; case "189": return "电信"; } } }
祝你好运!!!