package org.springblade.face.util.ipaddress;


import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class CityUtil {

	private static City cityDb;

	private static ClassPathResource cpr;
	
	static {
		cpr = new ClassPathResource("/addressdb/ipipfree.ipdb");
	}

	public static String getAddress(String ip) {
		try {
			cityDb = new City(cpr.getInputStream());
			CityInfo cityInfo = cityDb.findCity(ip, "CN");
			return cityInfo.toString();
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	public static void main(String[] args) {
		System.out.println(getAddress("1.68.1.255"));
	}
}
