• AddressUtils


    package com.ruoyi.common.utils;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import com.ruoyi.common.config.Global;
    import com.ruoyi.common.json.JSON;
    import com.ruoyi.common.json.JSONObject;
    import com.ruoyi.common.utils.http.HttpUtils;
    
    /**
     * 获取地址类
     * 
     * @author ruoyi
     */
    public class AddressUtils
    {
        private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
    
        public static final String IP_URL = "http://ip.taobao.com/service/getIpInfo.php";
    
        public static String getRealAddressByIP(String ip)
        {
            String address = "XX XX";
    
            // 内网不查询
            if (IpUtils.internalIp(ip))
            {
                return "内网IP";
            }
            if (Global.isAddressEnabled())
            {
                String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
                if (StringUtils.isEmpty(rspStr))
                {
                    log.error("获取地理位置异常 {}", ip);
                    return address;
                }
                JSONObject obj;
                try
                {
                    obj = JSON.unmarshal(rspStr, JSONObject.class);
                    JSONObject data = obj.getObj("data");
                    String region = data.getStr("region");
                    String city = data.getStr("city");
                    address = region + " " + city;
                }
                catch (Exception e)
                {
                    log.error("获取地理位置异常 {}", ip);
                }
            }
            return address;
        }
    }
  • 相关阅读:
    python列表切片
    python注释行与段落
    PCL安装与配置
    自动驾驶相关
    (转)ping命令
    (转)linux应用之test命令详细解析
    (转)shell解析命令行的过程以及eval命令
    (转)ssh-keygen 中文手册
    (转)stty 命令说明及使用讲解
    (转)CentOS下的trap命令
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/11750376.html
Copyright © 2020-2023  润新知