public static String[] getMobileAddress(String mobile) throws Exception {
String[] mobileInfo = new String[2];
try {
mobile = mobile.trim();
if (mobile.matches("^(13|14|15|18)\\d{9}$")
|| mobile.matches("^(013|014|015|018)\\d{9}$")) // 以13,14,15,18开头,后面九位全为数字
{
String url = "http://www.ip138.com:8080/search.asp?action=mobile&mobile="
+ mobile;
URLConnection connection = (URLConnection) new URL(url)
.openConnection();
connection.setDoOutput(true);
InputStream os = connection.getInputStream();
Thread.sleep(100);
int length = os.available();
byte[] buff = new byte[length];
os.read(buff);
String s = new String(buff, "gbk");
s = s.substring(s.indexOf("卡号归属地"), s.indexOf("区 号"));
s = s.replaceAll("\\w", "").replaceAll("\\p{Punct}", "")
.replaceAll("\\s", "");
if (s.indexOf("卡号归属地") > -1) {
String address = s.replace("卡号归属地", "");
address = address.substring(0, address.lastIndexOf("卡类型"));
mobileInfo[0] = address;
System.out.println(address);
}
if (s.indexOf("卡类型") > -1) {
String type = s.substring(s.indexOf("卡类型") + 3, s.length());
mobileInfo[1] = type;
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载