Skip to content

Commit cd382e7

Browse files
committed
Added IPTools class.
1 parent 8497035 commit cd382e7

File tree

6 files changed

+456
-7
lines changed

6 files changed

+456
-7
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.com
3+
Copyright (c) 2022 IP2Location.com
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: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,51 @@ ws.lookup(ip, addon, lang, (err, data) => {
150150
}
151151
});
152152

153-
```
153+
```
154+
155+
## IPTOOLS CLASS
156+
157+
## Methods
158+
Below are the methods supported in this module.
159+
160+
|Method Name|Description|
161+
|---|---|
162+
|isIPV4(myIP)|Returns true if string contains an IPv4 address. Otherwise false.|
163+
|isIPV6(myIP)|Returns true if string contains an IPv6 address. Otherwise false.|
164+
|ipV4ToDecimal(myIP)|Returns the IP number for an IPv4 address.|
165+
|ipV6ToDecimal(myIP)|Returns the IP number for an IPv6 address.|
166+
|decimalToIPV4(ipNum)|Returns the IPv4 address for the supplied IP number.|
167+
|decimalToIPV6(ipNum)|Returns the IPv6 address for the supplied IP number.|
168+
|compressIPV6(myIP)|Returns the IPv6 address in compressed form.|
169+
|expandIPV6(myIP)|Returns the IPv6 address in expanded form.|
170+
|ipV4ToCIDR(ipFrom, ipTo)|Returns a list of CIDR from the supplied IPv4 range.|
171+
|ipV6ToCIDR(ipFrom, ipTo)|Returns a list of CIDR from the supplied IPv6 range.|
172+
|cidrToIPV4(cidr)|Returns the IPv4 range from the supplied CIDR.|
173+
|cidrToIPV6(cidr)|Returns the IPv6 range from the supplied CIDR.|
174+
175+
## Usage
176+
177+
```javascript
178+
const {IPTools} = require("ip2location-nodejs");
179+
180+
let tools = new IPTools();
181+
182+
console.log(tools.isIPV4("60.54.166.38"));
183+
console.log(tools.isIPV6("2001:4860:4860::8888"));
184+
console.log(tools.ipV4ToDecimal("60.54.166.38"));
185+
console.log(tools.ipV6ToDecimal("2001:4860:4860::8888"));
186+
console.log(tools.decimalToIPV4(1010214438));
187+
console.log(tools.decimalToIPV6("530610913025797008819807084026527744"));
188+
console.log(tools.compressIPV6("66:3123:4860:3234:411:23:000:000"));
189+
console.log(tools.expandIPV6("66:023:40:34:411:23:000:000"));
190+
let cidr = tools.ipV4ToCIDR("10.0.0.0", "10.10.2.255");
191+
for (const x of cidr) {
192+
console.log(x);
193+
}
194+
cidr = tools.ipV6ToCIDR("2001:4860:4860:0000:0000:0000:0000:8888", "2001:4860:4860:0000:eeee:ffff:ffff:ffff");
195+
for (const x of cidr) {
196+
console.log(x);
197+
}
198+
console.log(tools.cidrToIPV4("10.123.80.0/12"));
199+
console.log(tools.cidrToIPV6("2002:1234::abcd:ffff:c0a8:101/62"));
200+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ip2location-nodejs",
3-
"version": "9.1.0",
3+
"version": "9.2.0",
44
"description": "IP2Location geolocation component",
55
"keywords": [
66
"ip2location",

src/ip2location.d.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,20 @@ export class IP2LocationWebService {
9797
lookup(myIP: any, addOn: any, lang: any, callback: any): void;
9898
getCredit(callback: any): void;
9999
#private;
100-
}
100+
}
101+
export class IPTools {
102+
isIPV4(myIP: any): any;
103+
isIPV6(myIP: any): any;
104+
ipV4ToDecimal(myIP: any): number;
105+
ipV6ToDecimal(myIP: any): any;
106+
decimalToIPV4(ipNum: any): string;
107+
decimalToIPV6(ipNum: any): any;
108+
compressIPV6(myIP: any): any;
109+
expandIPV6(myIP: any): any;
110+
ipV4ToCIDR(ipFrom: any, ipTo: any): string[];
111+
ipToBinary(myIP: any): any;
112+
binaryToIP(myBin: any): any;
113+
ipV6ToCIDR(ipFrom: any, ipTo: any): string[];
114+
cidrToIPV4(cidr: any): string[];
115+
cidrToIPV6(cidr: any): any[];
116+
}

0 commit comments

Comments
 (0)