Skip to content

Commit 4b26e3b

Browse files
Added IPTools class
1 parent 0a01ffd commit 4b26e3b

File tree

6 files changed

+594
-8
lines changed

6 files changed

+594
-8
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 IP2Location
3+
Copyright (c) 2022 IP2Location
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,69 @@ public class Main
333333
}
334334

335335
```
336+
337+
## IPTOOLS CLASS
338+
339+
## Methods
340+
Below are the methods supported in this class.
341+
342+
|Method Name|Description|
343+
|---|---|
344+
|public boolean IsIPv4(String IPAddress)|Returns true if string contains an IPv4 address. Otherwise false.|
345+
|public boolean IsIPv6(String IPAddress)|Returns true if string contains an IPv6 address. Otherwise false.|
346+
|public BigInteger IPv4ToDecimal(String IPAddress)|Returns the IP number for an IPv4 address.|
347+
|public BigInteger IPv6ToDecimal(String IPAddress)|Returns the IP number for an IPv6 address.|
348+
|public String DecimalToIPv4(BigInteger IPNum)|Returns the IPv4 address for the supplied IP number.|
349+
|public String DecimalToIPv6(BigInteger IPNum)|Returns the IPv6 address for the supplied IP number.|
350+
|public String CompressIPv6(String IPAddress)|Returns the IPv6 address in compressed form.|
351+
|public String ExpandIPv6(String IPAddress)|Returns the IPv6 address in expanded form.|
352+
|public List<String> IPv4ToCIDR(String IPFrom, String IPTo)|Returns a list of CIDR from the supplied IPv4 range.|
353+
|public List<String> IPv6ToCIDR(String IPFrom, String IPTo)|Returns a list of CIDR from the supplied IPv6 range.|
354+
|public String[] CIDRToIPv4(String CIDR)|Returns the IPv4 range from the supplied CIDR.|
355+
|public String[] CIDRToIPv6(String CIDR)|Returns the IPv6 range from the supplied CIDR.|
356+
357+
## Usage
358+
359+
```java
360+
import com.ip2location.*;
361+
import java.math.BigInteger;
362+
import java.util.*;
363+
364+
public class Main
365+
{
366+
public Main()
367+
{
368+
}
369+
public static void main(String[] args)
370+
{
371+
try
372+
{
373+
IPTools tools = new IPTools();
374+
375+
System.out.println(tools.IsIPv4("60.54.166.38"));
376+
System.out.println(tools.IsIPv6("2600:1f18:45b0:5b00:f5d8:4183:7710:ceec"));
377+
System.out.println(tools.IPv4ToDecimal("60.54.166.38"));
378+
System.out.println(tools.IPv6ToDecimal("2600:118:450:5b00:f5d8:4183:7710:ceec"));
379+
System.out.println(tools.DecimalToIPv4(new BigInteger("1010214438")));
380+
System.out.println(tools.DecimalToIPv6(new BigInteger("50510686025047391022278667396705210092")));
381+
System.out.println(tools.CompressIPv6("0000:0000:0000:0035:0000:FFFF:0000:0000"));
382+
System.out.println(tools.ExpandIPv6("500:6001:FE:35:0:FFFF::"));
383+
List<String> stuff = tools.IPv4ToCIDR("10.0.0.0", "10.10.2.255");
384+
stuff.forEach(System.out::println);
385+
List<String> stuff2 = tools.IPv6ToCIDR("2001:4860:4860:0000:0000:0000:0000:8888", "2001:4860:4860:0000:eeee:ffff:ffff:ffff");
386+
stuff2.forEach(System.out::println);
387+
String[] stuff3 = tools.CIDRToIPv4("10.123.80.0/12");
388+
System.out.println(stuff3[0]);
389+
System.out.println(stuff3[1]);
390+
String[] stuff4 = tools.CIDRToIPv6("2002:1234::abcd:ffff:c0a8:101/62");
391+
System.out.println(stuff4[0]);
392+
System.out.println(stuff4[1]);
393+
}
394+
catch(Exception e)
395+
{
396+
System.out.println(e);
397+
e.printStackTrace(System.out);
398+
}
399+
}
400+
}
401+
```

com/ip2location/IP2Location.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
* <p>
3333
* <b>Requirements:</b> Java SDK 1.4 or later<br>
3434
* <p>
35-
* Copyright (c) 2002-2021 IP2Location.com
35+
* Copyright (c) 2002-2022 IP2Location.com
3636
* <p>
3737
*
3838
* @author IP2Location.com
39-
* @version 8.7.0
39+
* @version 8.8.0
4040
*/
4141
public class IP2Location {
4242
private static final Pattern pattern = Pattern.compile("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); // IPv4

com/ip2location/IP2LocationWebService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
* <p>
2525
* <b>Requirements:</b> Java SDK 1.4 or later<br>
2626
* <p>
27-
* Copyright (c) 2002-2021 IP2Location.com
27+
* Copyright (c) 2002-2022 IP2Location.com
2828
* <p>
2929
*
3030
* @author IP2Location.com
31-
* @version 8.7.0
31+
* @version 8.8.0
3232
*/
3333
public class IP2LocationWebService {
3434
private static final Pattern pattern = Pattern.compile("^[\\dA-Z]{10}$");

com/ip2location/IPResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* <p>
66
* <b>Requirements:</b> Java SDK 1.4 or later<br>
77
* <p>
8-
* Copyright (c) 2002-2021 IP2Location.com
8+
* Copyright (c) 2002-2022 IP2Location.com
99
* <p>
1010
*
1111
* @author IP2Location.com
12-
* @version 8.7.0
12+
* @version 8.8.0
1313
*/
1414
public class IPResult {
1515
static final String NOT_SUPPORTED = "Not_Supported";
@@ -38,7 +38,7 @@ public class IPResult {
3838
String category;
3939
String status;
4040
boolean delay = false;
41-
String version = "Version 8.7.0";
41+
String version = "Version 8.8.0";
4242

4343
IPResult(String ipstring) {
4444
ip_address = ipstring;

0 commit comments

Comments
 (0)