Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/main/java/net/ipip/ipdb/Reader.java
Original file line number Diff line number Diff line change
@@ -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;


Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down