{"id":23251369,"url":"https://github.com/renfei/ip2location","last_synced_at":"2025-04-07T16:18:17.517Z","repository":{"id":41372175,"uuid":"429657128","full_name":"renfei/ip2location","owner":"renfei","description":"IP2Location™ for Java Client and database bin file.","archived":false,"fork":false,"pushed_at":"2025-03-01T09:05:24.000Z","size":2036746,"stargazers_count":74,"open_issues_count":6,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T15:18:15.789Z","etag":null,"topics":["ip2location","ip2location-bin-database","ip2location-bin-databases","ip2location-database","ip2location-java","ip2location-maven","ipdatabase","java"],"latest_commit_sha":null,"homepage":"https://lite.ip2location.com/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renfei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-19T03:24:34.000Z","updated_at":"2025-03-27T03:10:44.000Z","dependencies_parsed_at":"2024-05-01T11:02:08.035Z","dependency_job_id":"f3224834-66c6-40dc-90f7-fac1b78fd7b8","html_url":"https://github.com/renfei/ip2location","commit_stats":{"total_commits":69,"total_committers":3,"mean_commits":23.0,"dds":0.3913043478260869,"last_synced_commit":"289129d7ed2a410f8ac69daebe705c4312742fc9"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfei%2Fip2location","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfei%2Fip2location/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfei%2Fip2location/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renfei%2Fip2location/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renfei","download_url":"https://codeload.github.com/renfei/ip2location/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247685628,"owners_count":20979085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ip2location","ip2location-bin-database","ip2location-bin-databases","ip2location-database","ip2location-java","ip2location-maven","ipdatabase","java"],"created_at":"2024-12-19T09:17:59.455Z","updated_at":"2025-04-07T16:18:17.477Z","avatar_url":"https://github.com/renfei.png","language":"Java","funding_links":[],"categories":["网络编程"],"sub_categories":["Spring Cloud框架"],"readme":"[简体中文](./README_zh.md) | [English](./README.md)\n\n![./doc/logo.png](./doc/logo.png)\n\n\u003e This site or product includes IP2Location LITE data available from http://www.ip2location.com\n\n# IP2Location for Java\n\nThe repository code is based on [ip2location repository](https://github.com/ip2location/ip2location-java).\n\nExample: [https://www.renfei.net/kitbox/ip](https://www.renfei.net/kitbox/ip)\n\n## Download\n\nThe update cycle of database bin file is once a month.\n\nDatabase bin file:\n\n- [Releases](https://github.com/renfei/ip2location/releases)\n\nOr download the zip file in the warehouse and decompress it by yourself.\n\n- [IP2LOCATION-LITE-DB11.BIN.ZIP](./IP2LOCATION-LITE-DB11.BIN.ZIP)\n- [IP2LOCATION-LITE-DB11.IPV6.BIN.ZIP](./IP2LOCATION-LITE-DB11.IPV6.BIN.ZIP)\n\n## Installing in maven\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.renfei\u003c/groupId\u003e\n    \u003cartifactId\u003eip2location\u003c/artifactId\u003e\n    \u003cversion\u003e1.2.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nCompared with the official client, I removed the ip2locationweb service and the dependency on other libraries.\n\n## Usage\n\n```java\nimport net.renfei.ip2location.*;\n\npublic class Main {\n    public Main() {\n    }\n\n    public static void main(String[] args) {\n        IP2Location loc = new IP2Location();\n        try {\n            String ip = \"8.8.8.8\";\n            String binfile = \"/usr/data/IP2LOCATION-LITE-DB11.BIN\";\n\n            // this is to initialize with a BIN file\n            loc.Open(binfile, true);\n\n            // this is to initialize with a byte array\n            // Path binpath = Paths.get(binfile);\n            // byte[] binFileBytes = Files.readAllBytes(binpath);\n            // loc.Open(binFileBytes);\n\n            IPResult rec = loc.IPQuery(ip);\n            if (\"OK\".equals(rec.getStatus())) {\n                System.out.println(rec);\n            } else if (\"EMPTY_IP_ADDRESS\".equals(rec.getStatus())) {\n                System.out.println(\"IP address cannot be blank.\");\n            } else if (\"INVALID_IP_ADDRESS\".equals(rec.getStatus())) {\n                System.out.println(\"Invalid IP address.\");\n            } else if (\"MISSING_FILE\".equals(rec.getStatus())) {\n                System.out.println(\"Invalid database path.\");\n            } else if (\"IPV6_NOT_SUPPORTED\".equals(rec.getStatus())) {\n                System.out.println(\"This BIN does not contain IPv6 data.\");\n            } else {\n                System.out.println(\"Unknown error.\" + rec.getStatus());\n            }\n            System.out.println(\"Java Component: \" + rec.getVersion());\n        } catch (Exception e) {\n            System.out.println(e);\n            e.printStackTrace(System.out);\n        } finally {\n            loc.Close();\n        }\n    }\n}\n```\n\n### Database Fields\n\n| Name         | Type                      | Description                                                           |\n|--------------|---------------------------|-----------------------------------------------------------------------|\n| ip_from      | INT (10) / DECIMAL (39,0) | First IP address show netblock.                                       |\n| ip_to        | INT (10) / DECIMAL (39,0) | Last IP address show netblock.                                        |\n| country_code | CHAR(2)                   | Two-character country code based on ISO 3166.                         |\n| country_name | VARCHAR(64)               | Country name based on ISO 3166.                                       |\n| region_name  | VARCHAR(128)              | Region or state name.                                                 |\n| city_name    | VARCHAR(128)              | City name.                                                            |\n| latitude     | DOUBLE                    | City latitude. Default to capital city latitude if city is unknown.   |\n| longitude    | DOUBLE                    | City longitude. Default to capital city longitude if city is unknown. |\n| zip_code     | VARCHAR(30)               | ZIP/Postal code.                                                      |\n| time_zone    | VARCHAR(8)                | UTC time zone (with DST supported).                                   |\n\n## IPTOOLS CLASS\n\n## Methods\n\nBelow are the methods supported in this class.\n\n| Method Name                                                | Description                                                       |\n|------------------------------------------------------------|-------------------------------------------------------------------|\n| public boolean IsIPv4(String IPAddress)                    | Returns true if string contains an IPv4 address. Otherwise false. |\n| public boolean IsIPv6(String IPAddress)                    | Returns true if string contains an IPv6 address. Otherwise false. |\n| public BigInteger IPv4ToDecimal(String IPAddress)          | Returns the IP number for an IPv4 address.                        |\n| public BigInteger IPv6ToDecimal(String IPAddress)          | Returns the IP number for an IPv6 address.                        |\n| public String DecimalToIPv4(BigInteger IPNum)              | Returns the IPv4 address for the supplied IP number.              |\n| public String DecimalToIPv6(BigInteger IPNum)              | Returns the IPv6 address for the supplied IP number.              |\n| public String CompressIPv6(String IPAddress)               | Returns the IPv6 address in compressed form.                      |\n| public String ExpandIPv6(String IPAddress)                 | Returns the IPv6 address in expanded form.                        |\n| public List\u003cString\u003e IPv4ToCIDR(String IPFrom, String IPTo) | Returns a list of CIDR from the supplied IPv4 range.              |\n| public List\u003cString\u003e IPv6ToCIDR(String IPFrom, String IPTo) | Returns a list of CIDR from the supplied IPv6 range.              |\n| public String[] CIDRToIPv4(String CIDR)                    | Returns the IPv4 range from the supplied CIDR.                    |\n| public String[] CIDRToIPv6(String CIDR)                    | Returns the IPv6 range from the supplied CIDR.                    |\n\n## Usage\n\n```java\nimport com.ip2location.*;\n\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n    public Main() {\n    }\n\n    public static void main(String[] args) {\n        try {\n            IPTools tools = new IPTools();\n\n            System.out.println(tools.IsIPv4(\"60.54.166.38\"));\n            System.out.println(tools.IsIPv6(\"2600:1f18:45b0:5b00:f5d8:4183:7710:ceec\"));\n            System.out.println(tools.IPv4ToDecimal(\"60.54.166.38\"));\n            System.out.println(tools.IPv6ToDecimal(\"2600:118:450:5b00:f5d8:4183:7710:ceec\"));\n            System.out.println(tools.DecimalToIPv4(new BigInteger(\"1010214438\")));\n            System.out.println(tools.DecimalToIPv6(new BigInteger(\"50510686025047391022278667396705210092\")));\n            System.out.println(tools.CompressIPv6(\"0000:0000:0000:0035:0000:FFFF:0000:0000\"));\n            System.out.println(tools.ExpandIPv6(\"500:6001:FE:35:0:FFFF::\"));\n            List\u003cString\u003e stuff = tools.IPv4ToCIDR(\"10.0.0.0\", \"10.10.2.255\");\n            stuff.forEach(System.out::println);\n            List\u003cString\u003e stuff2 = tools.IPv6ToCIDR(\"2001:4860:4860:0000:0000:0000:0000:8888\", \"2001:4860:4860:0000:eeee:ffff:ffff:ffff\");\n            stuff2.forEach(System.out::println);\n            String[] stuff3 = tools.CIDRToIPv4(\"10.123.80.0/12\");\n            System.out.println(stuff3[0]);\n            System.out.println(stuff3[1]);\n            String[] stuff4 = tools.CIDRToIPv6(\"2002:1234::abcd:ffff:c0a8:101/62\");\n            System.out.println(stuff4[0]);\n            System.out.println(stuff4[1]);\n        } catch (Exception e) {\n            System.out.println(e);\n            e.printStackTrace(System.out);\n        }\n    }\n}\n```\n\n## Mirror\n\n* [https://github.com/renfei/ip2location](https://github.com/renfei/ip2location)\n* [https://gitlab.com/renfei/ip2location](https://gitlab.com/renfei/ip2location)\n* [https://jihulab.com/renfei/ip2location](https://jihulab.com/renfei/ip2location)\n* [https://gitee.com/rnf/ip2location](https://gitee.com/rnf/ip2location)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenfei%2Fip2location","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenfei%2Fip2location","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenfei%2Fip2location/lists"}