From 4bd78ce6fed10b830701d8174850b67177f6bf4d Mon Sep 17 00:00:00 2001 From: yangbo Date: Sat, 1 Apr 2023 19:48:34 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E6=9B=BF=E6=8D=A2sun.net.util?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=EF=BC=8C=E6=94=AF=E6=8C=81jdk-17=E7=AD=89?= =?UTF-8?q?=E9=AB=98=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/net/ipip/ipdb/Reader.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/ipip/ipdb/Reader.java b/src/main/java/net/ipip/ipdb/Reader.java index 19f7372..1eec954 100644 --- a/src/main/java/net/ipip/ipdb/Reader.java +++ b/src/main/java/net/ipip/ipdb/Reader.java @@ -1,9 +1,10 @@ package net.ipip.ipdb; import com.alibaba.fastjson.JSONObject; -import sun.net.util.IPAddressUtil; import java.io.*; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Arrays; @@ -93,10 +94,14 @@ public String[] find(String addr, String language) throws IPFormatException, Inv return null; } - byte[] ipv; + byte[] ipv = null; if (addr.indexOf(":") > 0) { - ipv = IPAddressUtil.textToNumericFormatV6(addr); + try { + ipv = InetAddress.getByName(addr).getAddress(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } if (ipv == null) { throw new IPFormatException("ipv6 format error"); } @@ -105,7 +110,11 @@ public String[] find(String addr, String language) throws IPFormatException, Inv } } else if (addr.indexOf(".") > 0) { - ipv = IPAddressUtil.textToNumericFormatV4(addr); + try { + ipv = InetAddress.getByName(addr).getAddress(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } if (ipv == null) { throw new IPFormatException("ipv4 format error"); }