@@ -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+ ```
0 commit comments