Skip to content

Commit

Permalink
Merge pull request #83 from GoogleCloudPlatform/fix-ip
Browse files Browse the repository at this point in the history
Fix issue with truncating recorded ip addresses
  • Loading branch information
lesv committed Feb 5, 2016
2 parents ba9555d + 6e2cc56 commit a732ac5
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
String userIp = req.getRemoteAddr();
InetAddress address = InetAddress.getByName(userIp);
if (address instanceof Inet6Address) {
userIp = userIp.substring(0, userIp.indexOf(":", 2)) + ":*:*:*:*:*:*";
// nest indexOf calls to find the second occurrence of a character in a string
// an alternative is to use Apache Commons Lang: StringUtils.ordinalIndexOf()
userIp = userIp.substring(0, userIp.indexOf(":", userIp.indexOf(":") + 1)) + ":*:*:*:*:*:*";
} else if (address instanceof Inet4Address) {
userIp = userIp.substring(0, userIp.indexOf(".", 2)) + ".*.*";
userIp = userIp.substring(0, userIp.indexOf(".", userIp.indexOf(".") + 1)) + ".*.*";
}

final String createTableSql = "CREATE TABLE IF NOT EXISTS visits ( visit_id INT NOT NULL "
Expand Down

0 comments on commit a732ac5

Please sign in to comment.