您当前的位置: 首页 > 

宝哥大数据

暂无认证

  • 0浏览

    0关注

    1029博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

IP转换

宝哥大数据 发布时间:2021-01-31 12:54:40 ,浏览量:0

一、IP转化工具介绍

在这里插入图片描述

1.1、第三方工具对比

在这里插入图片描述

1.2、Ip2region使用 1.2.1、ip2region的引入
1、将数据集ip2region.db导入到工程下的dataset目录
2、导入依赖

    org.lionsoul
    ip2region
    1.7.2

2.2.2、使用
  @Test
  def ip2region(): Unit = {
    val searcher = new DbSearcher(new DbConfig(), "dataset/ip2region.db")
    val region = searcher.btreeSearch("61.152.197.181").getRegion
    println(region)
    // 国家|区域|省份|城市|ISP_
  }
1.3、GeoLite使用 1.3.1、依赖包

        
            com.maxmind.geoip2
            geoip2
            2.13.1
        
1.3.2、使用
  @Test
  /**
   * IP -> longtitude,latitude
   */
  def ip2Location(): Unit = {
    import com.maxmind.geoip2.DatabaseReader
    import com.maxmind.geoip2.model.CityResponse
    import com.maxmind.geoip2.record.City
    import com.maxmind.geoip2.record.Postal
    import com.maxmind.geoip2.record.Subdivision
    import java.net.InetAddress

    val database = new File("dataset/GeoLite2-City.mmdb")


    val reader: DatabaseReader = new DatabaseReader.Builder(database).build

    val ipAddress = InetAddress.getByName("128.101.101.101")

    val response = reader.city(ipAddress)

    val country = response.getCountry
    System.out.println(country.getIsoCode)
    System.out.println(country.getName)
    System.out.println(country.getNames.get("zh-CN"))

    val subdivision = response.getMostSpecificSubdivision
    System.out.println(subdivision.getName)
    System.out.println(subdivision.getIsoCode)

    val city = response.getCity
    System.out.println(city.getName)

    val postal = response.getPostal
    System.out.println(postal.getCode)

    val location = response.getLocation
    System.out.println(location.getLatitude)
    System.out.println(location.getLongitude)
  }
关注
打赏
1587549273
查看更多评论
立即登录/注册

微信扫码登录

0.0382s