今天分享一个免费在线的小工具的开发代码就是通过淘宝提供的接口获取服务商信息,
工具地址:http://www.yzcopen.com/seo/ipadress

代码如下:

public class YzcPattern {
/**
* ip地址接口
*/
private final static String ipurl ="http://ip.taobao.com/service/getIpInfo.php?ip="; /**
* 判断ip
* @param text
* @return
*/
public static boolean ipCheck(String text) {
if (text != null && !text.isEmpty()) {
// 定义正则表达式
String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
// 判断ip地址是否与正则表达式匹配
if (text.matches(regex)) {
return true;
// 返回判断信息
//return text + "\n是一个合法的IP地址!";
} else {
return false;
// 返回判断信息
//return text + "\n不是一个合法的IP地址!";
}
}
return false;
} /**
* 读取IP的
* @param getAccessTokenUrl
* @return
*/
public static String getAuth(String getAccessTokenUrl) {
HttpURLConnection connection = null;
try {
URL realUrl = new URL(getAccessTokenUrl);
// 打开和URL之间的连接
connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestProperty("User-Agent", Const.UserAgent);
connection.setRequestMethod("GET");
connection.setRequestProperty("Charsert", "UTF-8"); //设置请求编码
connection.setRequestProperty("Content-Type",
"application/json");
connection.connect();
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
String result = "";
String line;
while ((line = in.readLine()) != null) {
result += line;
}
/**
* 返回结果示例
*/
return result;
} catch (Exception e) {
e.printStackTrace();
}finally{
if(connection!=null){
connection.disconnect();
}
}
return null;
} public static void main(String[] args) throws Exception {
String ip="您的ip";
boolean bo = YzcPattern.ipCheck(ip);
if(bo){
String url = ipurl+ip;
String result = getAuth(url);
} //获得的结果 {"code":0,"data":{"ip":"58.87.124.194","country":"中国","area":"","region":"天津","city":"天津","county":"XX","isp":"电信","country_id":"CN","area_id":"","region_id":"120000","city_id":"120100","county_id":"xx","isp_id":"100017"}}
}
}

java通过免费接口获取ip地址的服务商信息的更多相关文章

  1. JAVA从本机获取IP地址

    JAVA从本机获取IP地址 论述: 此篇博客是在工作的时候,需要获得当前网络下面正确的ip地址,在网上查阅很多博客,网上一个比较普遍的说法是通过InetAddress.getLocalHost().g ...

  2. 获取ip地址及城市信息

    大家好,今天给大家分享的是一个简单的知识获取登录用户的ip地址及城市信息,lz是一个小白,如果有哪些错误的地方  欢迎大家指出 东西很简单,直接上代码 [HttpPost] public string ...

  3. thinkphp获取ip地址及位置信息

    ThinkPHP\Common\funcitons.php下有一个get_client_ip()能够获取ip地址 但是有时候不够准确 找到了下面一段来 function get_client_ip($ ...

  4. [转] JAVA从本机获取IP地址

    [From] https://www.cnblogs.com/xiaoBlog2016/p/7076230.html 论述: 此篇博客是在工作的时候,需要获得当前网络下面正确的ip地址,在网上查阅很多 ...

  5. java通过请求对象获取ip地址、获取ip地址

    /** * 获取登录ip */ public String getIp(){ HttpServletRequest request = this.getRequest(); String ip = & ...

  6. 前端借助接口获取ip地址

    <script language="javascript" src="http://www.codefans.net/ajaxjs/jquery1.3.2.js&q ...

  7. 正确JAVA从本机获取IP地址的方法

    https://www.cnblogs.com/xiaoBlog2016/p/7076230.html

  8. PHP 获取IP地址位置信息「聚合数据API」

    聚合数据 提供了[查询IP所属区域]的服务接口,只需要以 GET 请求的方式向 API 传入 IP地址 和 APPKEY 即可获得查询结果. 这里的难点主要在于如何通过PHP获取客户端IP地址,以及如 ...

  9. js获取IP地址方法总结_转

    js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338.html 1,js取得IP地址 ...

随机推荐

  1. nginx安装出现:cp: `conf/koi-win' and `/application/nginx-1.6.3/conf/koi-win' are the same file

    nginx编译安装时make出现如下错误 ]: Leaving directory `/application/nginx-' make -f objs/Makefile install ]: Ent ...

  2. swiper用axios异步请求后 循环失效

    解决方案 使用ajax动态获取数据  当数据还没有收到的时候,swiper组件收到的是跟组件data传过来的空数组,会造成渲染问题 这个时候可以给swiper组件 设置一个  v-if='list.l ...

  3. scala def方法时等号和括号使用说明笔记

    scala定义方法时会指定入参和返回类型(无返回类型时对应Unit,即java和C中的void模式). 1.有入参,有返回类型时,scala具有类型推导功能,以下两种表达方式效果一样.但根据scala ...

  4. 18 11 24 简单的http服务器

    ---恢复内容开始--- import socket def service_client(new_socket): """为这个客户端返回数据""& ...

  5. 使用axis调用webservice接口

    以前使用webservice服务都很简单,就是根据提供的wsdl接口地址,通过eclipse或者idea自动生成webservice client包,然后直接调用就可以了.这次业务提供的wsdl是需要 ...

  6. hdu 2072(字典树模板,set,map均可做)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...

  7. [Python Cookbook]Pandas: How to increase columns for DataFrame?Join/Concat

    1. Combine Two Series series1=pd.Series([1,2,3],name='s1') series2=pd.Series([4,5,6],name='s2') df = ...

  8. Django2.0——中间件

    Django中间件middleware本质是一个类,在请求到返回的中间,类中不同的方法会在指定的时机中被触发.setting.py的变量MIDDLEWARE_CLASSES中的每一个元素都是中间件,且 ...

  9. 106.HttpResponse对象详解

    HttpResponse对象 Django服务器接收到客户端发送过来的请求之后,会将提交上来的这些数据封装成一个HttpResquest对象传给视图函数.那么视图函数在处理完成相关的逻辑后,也需要返回 ...

  10. CSS 之pseudo-classes 与pseudo-element的异同

    从W3School找到相关资料如下: 伪类: 伪类存在的意义是为了通过选择器找到那些不存在与DOM树中的信息以及不能被常规CSS选择器获取到的信息. 伪类由一个冒号:开头,冒号后面是伪类的名称和包含在 ...