Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lodsve.boot.component.webmvc.utils;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.*;
/**
* 操作ip的工具类.
*
* @author sunhao([email protected])
* @date 13-12-10 下午11:37
*/
public class IpUtils {
private static final Logger logger = LoggerFactory.getLogger(IpUtils.class);
/**
* 默认的识别IP的地址(第三方运营商)
*/
private static final String REQUEST_URL = "http://ip.taobao.com/service/getIpInfo.php?ip=%s";
/**
* 私有化构造器
*/
private IpUtils() {
}
/**
* 根据给定IP获取IP地址的全部信息
* eg:
* give ip 222.94.109.17,you will receive a map.
* map is {"region":"江苏省","area_id":"300000","country_id":"CN","isp":"电信","region_id":"320000","country":"中国","city":"南京市","isp_id":"100017","ip":"222.94.109.17","city_id":"320100","area":"华东","county":"","county_id":"-1"}
*
* @param ip ip
* @return IP地址的全部信息
*/
@SuppressWarnings("unchecked")
public static Map getAllInfo(String ip) {
if (StringUtils.isEmpty(ip)) {
logger.error("ip is null!!!");
return Collections.emptyMap();
}
Map message = RestUtils.getRestTemplate().exchange(String.format(REQUEST_URL, ip), HttpMethod.GET, null, new ParameterizedTypeReference