@gibme/ipinfo 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -19
- package/README.md +9 -9
- package/dist/helpers.d.ts +5 -0
- package/dist/helpers.js +146 -0
- package/dist/helpers.js.map +1 -0
- package/dist/ipinfo.d.ts +9 -37
- package/dist/ipinfo.js +46 -180
- package/dist/ipinfo.js.map +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/types.js +22 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -56
package/LICENSE
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Copyright (c) 2016-2023 Brandon Lehmann
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
-
SOFTWARE.
|
|
1
|
+
Copyright (c) 2016-2023 Brandon Lehmann
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Simple IP Information Lookup via [Team CYMRU](https://www.team-cymru.com/ip-asn-mapping)
|
|
2
|
-
|
|
3
|
-
```javascript
|
|
4
|
-
import IPInfo from '@gibme/ipinfo';
|
|
5
|
-
|
|
6
|
-
(async () => {
|
|
7
|
-
console.log(await IPInfo('1.1.1.1'));
|
|
8
|
-
})();
|
|
9
|
-
```
|
|
1
|
+
# Simple IP Information Lookup via [Team CYMRU](https://www.team-cymru.com/ip-asn-mapping)
|
|
2
|
+
|
|
3
|
+
```javascript
|
|
4
|
+
import IPInfo from '@gibme/ipinfo';
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
console.log(await IPInfo('1.1.1.1'));
|
|
8
|
+
})();
|
|
9
|
+
```
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2016-2023, Brandon Lehmann <brandonlehmann@gmail.com>
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const promises_1 = require("dns/promises");
|
|
32
|
+
/** @ignore */
|
|
33
|
+
const sleep = (timeout) => __awaiter(void 0, void 0, void 0, function* () { return new Promise(resolve => setTimeout(resolve, timeout)); });
|
|
34
|
+
/** @ignore */
|
|
35
|
+
const countColons = (value) => {
|
|
36
|
+
let count = 0;
|
|
37
|
+
value.replace(/:/g, val => { count++; return val; });
|
|
38
|
+
return count;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* @ignore
|
|
42
|
+
* Expands compressed IPv6 address to uncompressed form
|
|
43
|
+
*
|
|
44
|
+
* @param value
|
|
45
|
+
*/
|
|
46
|
+
const expandIPv6 = (value) => {
|
|
47
|
+
return value.replace(/::/, () => {
|
|
48
|
+
return `:${Array((7 - countColons(value)) + 1).join(':')}:`;
|
|
49
|
+
})
|
|
50
|
+
.split(':')
|
|
51
|
+
.map(val => {
|
|
52
|
+
return Array(4 - val.length).fill('0').join('') + val;
|
|
53
|
+
})
|
|
54
|
+
.join(':');
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* DNS TXT record resolution with automatic retries
|
|
58
|
+
*
|
|
59
|
+
* @param hostname
|
|
60
|
+
* @param max_retries
|
|
61
|
+
* @param retry
|
|
62
|
+
* @ignore
|
|
63
|
+
*/
|
|
64
|
+
const getTxtRecord = (hostname, max_retries = 3, retry = 0) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
return yield (0, promises_1.resolveTxt)(hostname);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error.toString().toLowerCase().includes('refused') && retry < max_retries) {
|
|
70
|
+
yield sleep(1000);
|
|
71
|
+
return getTxtRecord(hostname, max_retries, retry);
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Looks up information on the Autonomous System Number (ASN) via DNS
|
|
78
|
+
*
|
|
79
|
+
* @param as
|
|
80
|
+
* @param max_retries
|
|
81
|
+
* @ignore
|
|
82
|
+
*/
|
|
83
|
+
const getASN = (as, max_retries = 3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
if (typeof as === 'string') {
|
|
85
|
+
as = parseInt(as);
|
|
86
|
+
}
|
|
87
|
+
const records = yield getTxtRecord(`AS${as}.asn.cymru.com`, max_retries);
|
|
88
|
+
if (records.length === 0 || records[0].length === 0) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const [, country, registry, allocated, name] = records[0][0].split('|')
|
|
92
|
+
.map(elem => elem.trim());
|
|
93
|
+
return {
|
|
94
|
+
asn: as,
|
|
95
|
+
country: country.toUpperCase(),
|
|
96
|
+
registry: registry.toUpperCase(),
|
|
97
|
+
allocated: new Date(allocated),
|
|
98
|
+
name: name.split(',')[0]
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* Looks up the prefix information via DNS
|
|
103
|
+
*
|
|
104
|
+
* @param address
|
|
105
|
+
* @param max_retries
|
|
106
|
+
* @ignore
|
|
107
|
+
*/
|
|
108
|
+
const getPrefix = (address, max_retries = 3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const original_address = address;
|
|
110
|
+
address = address.split('/')[0]; // strip off any CIDR notation
|
|
111
|
+
if (address.includes(':')) {
|
|
112
|
+
address = expandIPv6(address);
|
|
113
|
+
address = address.split(':')
|
|
114
|
+
.join('')
|
|
115
|
+
.split('')
|
|
116
|
+
.reverse()
|
|
117
|
+
.join('.');
|
|
118
|
+
address = `${address}.origin6.asn.cymru.com`;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
address = address.split('.')
|
|
122
|
+
.reverse()
|
|
123
|
+
.join('.');
|
|
124
|
+
address = `${address}.origin.asn.cymru.com`;
|
|
125
|
+
}
|
|
126
|
+
const records = yield getTxtRecord(address, max_retries);
|
|
127
|
+
if (records.length === 0 || records[0].length === 0) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const [asn, prefix, country, registry, allocated] = records[0][0].split('|')
|
|
131
|
+
.map(elem => elem.trim());
|
|
132
|
+
return {
|
|
133
|
+
address: original_address,
|
|
134
|
+
zone: address,
|
|
135
|
+
asn: parseInt(asn),
|
|
136
|
+
prefix,
|
|
137
|
+
country: country.toUpperCase(),
|
|
138
|
+
registry: registry.toUpperCase(),
|
|
139
|
+
allocated: new Date(allocated),
|
|
140
|
+
as: yield getASN(asn)
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
exports.default = {
|
|
144
|
+
getPrefix
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;;;;;;;;;;;AAEZ,2CAA0C;AAG1C,cAAc;AACd,MAAM,KAAK,GAAG,CAAO,OAAe,EAAE,EAAE,kDACpC,OAAA,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,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EAAE,MAAM,MAAM,CAAC,GAAG,CAAC;KACV,CAAC;AACpB,CAAC,CAAA,CAAC;AAEF,kBAAe;IACX,SAAS;CACZ,CAAC"}
|
package/dist/ipinfo.d.ts
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
registry: string;
|
|
11
|
-
allocated: Date;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* ASN information
|
|
15
|
-
*/
|
|
16
|
-
export interface ASNEntry {
|
|
17
|
-
asn: number;
|
|
18
|
-
country: string;
|
|
19
|
-
registry: string;
|
|
20
|
-
allocated: Date;
|
|
21
|
-
name: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* IP Prefix information including the ASN name (if available)
|
|
25
|
-
*/
|
|
26
|
-
export interface IPInfo extends PrefixEntry {
|
|
27
|
-
as?: ASNEntry;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Looks up information regarding the IP address supplied
|
|
31
|
-
*
|
|
32
|
-
* @param address
|
|
33
|
-
* @param maxRetries
|
|
34
|
-
* @param retry
|
|
35
|
-
*/
|
|
36
|
-
export declare const IPInfo: (address: string, maxRetries?: number, retry?: number) => Promise<IPInfo>;
|
|
37
|
-
export default IPInfo;
|
|
1
|
+
import { PrefixInfo } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Looks up information regarding the IP address supplied
|
|
4
|
+
*
|
|
5
|
+
* @param address
|
|
6
|
+
* @param max_retries
|
|
7
|
+
*/
|
|
8
|
+
export declare const IPInfo: (address: string, max_retries?: number) => Promise<PrefixInfo | undefined>;
|
|
9
|
+
export default IPInfo;
|
package/dist/ipinfo.js
CHANGED
|
@@ -1,181 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) 2016-2023, Brandon Lehmann <brandonlehmann@gmail.com>
|
|
3
|
-
//
|
|
4
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
// in the Software without restriction, including without limitation the rights
|
|
7
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
// furnished to do so, subject to the following conditions:
|
|
10
|
-
//
|
|
11
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
// copies or substantial portions of the Software.
|
|
13
|
-
//
|
|
14
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
// SOFTWARE.
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.IPInfo = void 0;
|
|
55
|
-
const dns = __importStar(require("dns"));
|
|
56
|
-
/** @ignore */
|
|
57
|
-
const sleep = (timeout) => __awaiter(void 0, void 0, void 0, function* () { return new Promise(resolve => setTimeout(resolve, timeout)); });
|
|
58
|
-
/** @ignore */
|
|
59
|
-
const countColons = (value) => {
|
|
60
|
-
let count = 0;
|
|
61
|
-
value.replace(/:/g, val => { count++; return val; });
|
|
62
|
-
return count;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* @ignore
|
|
66
|
-
* Expands compressed IPv6 address to uncompressed form
|
|
67
|
-
*
|
|
68
|
-
* @param value
|
|
69
|
-
*/
|
|
70
|
-
const expandIPv6 = (value) => {
|
|
71
|
-
return value.replace(/::/, () => {
|
|
72
|
-
return `:${Array((7 - countColons(value)) + 1).join(':')}:`;
|
|
73
|
-
})
|
|
74
|
-
.split(':')
|
|
75
|
-
.map(val => {
|
|
76
|
-
return Array(4 - val.length).fill('0').join('') + val;
|
|
77
|
-
})
|
|
78
|
-
.join(':');
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* @ignore
|
|
82
|
-
* Looks up the prefix information via DNS
|
|
83
|
-
*
|
|
84
|
-
* @param address
|
|
85
|
-
*/
|
|
86
|
-
const prefix = (address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const _address = address;
|
|
89
|
-
address = address.split('/')[0]; // strip off any CIDR notation
|
|
90
|
-
if (address.includes(':')) {
|
|
91
|
-
address = expandIPv6(address);
|
|
92
|
-
address = address.split(':')
|
|
93
|
-
.join('')
|
|
94
|
-
.split('')
|
|
95
|
-
.reverse()
|
|
96
|
-
.join('.');
|
|
97
|
-
address = `${address}.origin6.asn.cymru.com`;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
address = address.split('.')
|
|
101
|
-
.reverse()
|
|
102
|
-
.join('.');
|
|
103
|
-
address = `${address}.origin.asn.cymru.com`;
|
|
104
|
-
}
|
|
105
|
-
dns.resolveTxt(address, (error, records) => {
|
|
106
|
-
if (error) {
|
|
107
|
-
return reject(error);
|
|
108
|
-
}
|
|
109
|
-
if (records.length === 0 || records[0].length === 0) {
|
|
110
|
-
throw new Error('No records found');
|
|
111
|
-
}
|
|
112
|
-
const [asn, prefix, country, registry, allocated] = records[0][0].split('|')
|
|
113
|
-
.map(elem => elem.trim());
|
|
114
|
-
return resolve({
|
|
115
|
-
address: _address,
|
|
116
|
-
zone: address,
|
|
117
|
-
asn: parseInt(asn),
|
|
118
|
-
prefix,
|
|
119
|
-
country: country.toUpperCase(),
|
|
120
|
-
registry: registry.toUpperCase(),
|
|
121
|
-
allocated: new Date(allocated)
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
/**
|
|
127
|
-
* @ignore
|
|
128
|
-
* Looks up information on the ASN via DNS
|
|
129
|
-
*
|
|
130
|
-
* @param as
|
|
131
|
-
*/
|
|
132
|
-
const asn = (as) => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
-
return new Promise((resolve, reject) => {
|
|
134
|
-
dns.resolveTxt(`AS${as}.asn.cymru.com`, (error, records) => {
|
|
135
|
-
if (error) {
|
|
136
|
-
return reject(error);
|
|
137
|
-
}
|
|
138
|
-
if (records.length === 0 || records[0].length === 0) {
|
|
139
|
-
throw new Error('No records found');
|
|
140
|
-
}
|
|
141
|
-
const [, country, registry, allocated, name] = records[0][0].split('|')
|
|
142
|
-
.map(elem => elem.trim());
|
|
143
|
-
return resolve({
|
|
144
|
-
asn: as,
|
|
145
|
-
country: country.toUpperCase(),
|
|
146
|
-
registry: registry.toUpperCase(),
|
|
147
|
-
allocated: new Date(allocated),
|
|
148
|
-
name
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
/**
|
|
154
|
-
* Looks up information regarding the IP address supplied
|
|
155
|
-
*
|
|
156
|
-
* @param address
|
|
157
|
-
* @param maxRetries
|
|
158
|
-
* @param retry
|
|
159
|
-
*/
|
|
160
|
-
const IPInfo = (address, maxRetries = 3, retry = 0) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
-
try {
|
|
162
|
-
const info = yield prefix(address);
|
|
163
|
-
try {
|
|
164
|
-
const _asn = yield asn(info.asn);
|
|
165
|
-
return Object.assign(Object.assign({}, info), { as: _asn });
|
|
166
|
-
}
|
|
167
|
-
catch (_a) {
|
|
168
|
-
return Object.assign({}, info);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
if (error.toString().toLowerCase().includes('refused') && retry < maxRetries) {
|
|
173
|
-
yield sleep(1000);
|
|
174
|
-
return (0, exports.IPInfo)(address, maxRetries, retry++);
|
|
175
|
-
}
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
exports.IPInfo = IPInfo;
|
|
180
|
-
exports.default = exports.IPInfo;
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2016-2023, Brandon Lehmann <brandonlehmann@gmail.com>
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.IPInfo = void 0;
|
|
35
|
+
const helpers_1 = __importDefault(require("./helpers"));
|
|
36
|
+
/**
|
|
37
|
+
* Looks up information regarding the IP address supplied
|
|
38
|
+
*
|
|
39
|
+
* @param address
|
|
40
|
+
* @param max_retries
|
|
41
|
+
*/
|
|
42
|
+
const IPInfo = (address, max_retries = 3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
return helpers_1.default.getPrefix(address, max_retries);
|
|
44
|
+
});
|
|
45
|
+
exports.IPInfo = IPInfo;
|
|
46
|
+
exports.default = exports.IPInfo;
|
|
181
47
|
//# sourceMappingURL=ipinfo.js.map
|
package/dist/ipinfo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipinfo.js","sourceRoot":"","sources":["../src/ipinfo.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY
|
|
1
|
+
{"version":3,"file":"ipinfo.js","sourceRoot":"","sources":["../src/ipinfo.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;;;;;;;;;;;;;;;AAGZ,wDAAgC;AAEhC;;;;;GAKG;AACI,MAAM,MAAM,GAAG,CAClB,OAAe,EACf,WAAW,GAAG,CAAC,EACgB,EAAE;IACjC,OAAO,iBAAO,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACnD,CAAC,CAAA,CAAC;AALW,QAAA,MAAM,UAKjB;AAEF,kBAAe,cAAM,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASN information
|
|
3
|
+
*/
|
|
4
|
+
export interface ASNEntry {
|
|
5
|
+
asn: number;
|
|
6
|
+
country: string;
|
|
7
|
+
registry: string;
|
|
8
|
+
allocated: Date;
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* IP Prefix information including the ASN name (if available)
|
|
13
|
+
*/
|
|
14
|
+
export interface PrefixInfo {
|
|
15
|
+
address: string;
|
|
16
|
+
zone: string;
|
|
17
|
+
asn: number;
|
|
18
|
+
prefix: string;
|
|
19
|
+
country: string;
|
|
20
|
+
registry: string;
|
|
21
|
+
allocated: Date;
|
|
22
|
+
as?: ASNEntry;
|
|
23
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2016-2023, Brandon Lehmann <brandonlehmann@gmail.com>
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@gibme/ipinfo",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A simple IP information lookup helper using Team CYMRU services",
|
|
5
|
-
"main": "dist/ipinfo.js",
|
|
6
|
-
"types": "dist/ipinfo.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist/*"
|
|
9
|
-
],
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "yarn build:typescript",
|
|
13
|
-
"build:docs": "./node_modules/.bin/typedoc",
|
|
14
|
-
"build:typescript": "./node_modules/.bin/tsc",
|
|
15
|
-
"test": "yarn test:style && yarn test:mocha",
|
|
16
|
-
"test:
|
|
17
|
-
"test:
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"fix
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"@types/
|
|
43
|
-
"@
|
|
44
|
-
"@typescript-eslint/
|
|
45
|
-
"eslint": "^
|
|
46
|
-
"eslint
|
|
47
|
-
"eslint-
|
|
48
|
-
"eslint-plugin-
|
|
49
|
-
"eslint-plugin-
|
|
50
|
-
"eslint-plugin-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@gibme/ipinfo",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "A simple IP information lookup helper using Team CYMRU services",
|
|
5
|
+
"main": "dist/ipinfo.js",
|
|
6
|
+
"types": "dist/ipinfo.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/*"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "yarn build:typescript",
|
|
13
|
+
"build:docs": "./node_modules/.bin/typedoc",
|
|
14
|
+
"build:typescript": "./node_modules/.bin/tsc",
|
|
15
|
+
"test": "yarn test:style && yarn test:typecheck && yarn test:mocha",
|
|
16
|
+
"test:typecheck": "./node_modules/.bin/tsc --noEmit",
|
|
17
|
+
"test:style": "yarn style",
|
|
18
|
+
"test:mocha": "./node_modules/.bin/mocha --exit --timeout 30000 --require ts-node/register test/test.ts",
|
|
19
|
+
"style": "./node_modules/.bin/eslint src/**/*.ts test/**/*.ts",
|
|
20
|
+
"fix-style": "./node_modules/.bin/eslint --fix src/**/*.ts test/**/*.ts",
|
|
21
|
+
"fix:style": "yarn fix-style",
|
|
22
|
+
"prepublishOnly": "yarn build"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/gibme-npm/ipinfo.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/gibme-npm/ipinfo/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://gibme-npm.github.io/ipinfo/",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=16"
|
|
34
|
+
},
|
|
35
|
+
"engineStrict": true,
|
|
36
|
+
"author": {
|
|
37
|
+
"name": "Brandon Lehmann",
|
|
38
|
+
"email": "brandonlehmann@gmail.com"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/mocha": "^10.0.1",
|
|
43
|
+
"@types/node": "^20.4.8",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
45
|
+
"@typescript-eslint/parser": "^6.2.1",
|
|
46
|
+
"eslint": "^8.46.0",
|
|
47
|
+
"eslint-config-standard": "^17.1.0",
|
|
48
|
+
"eslint-plugin-import": "^2.28.0",
|
|
49
|
+
"eslint-plugin-n": "^16.0.1",
|
|
50
|
+
"eslint-plugin-node": "^11.1.0",
|
|
51
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
52
|
+
"mocha": "^10.2.0",
|
|
53
|
+
"ts-node": "^10.9.1",
|
|
54
|
+
"typedoc": "^0.24.8",
|
|
55
|
+
"typescript": "^5.1.6"
|
|
56
|
+
}
|
|
57
|
+
}
|