get-device-ip 1.0.1 → 1.0.2
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/README.md +24 -5
- package/dist/script.js +61 -0
- package/dist/script.mjs +31 -0
- package/package.json +18 -4
- package/script.js +0 -42
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
6
|
A ultra-lightweight, zero-dependency Node.js utility to quickly find your machine's local IPv4 and IPv6 addresses.
|
|
7
|
+
### Use this for Backend development
|
|
7
8
|
|
|
8
9
|
### 🌟 Why use this?
|
|
9
10
|
|
|
@@ -18,16 +19,34 @@ A ultra-lightweight, zero-dependency Node.js utility to quickly find your machin
|
|
|
18
19
|
|
|
19
20
|
```bash
|
|
20
21
|
npm install get-device-ip
|
|
22
|
+
🚀 Usage
|
|
23
|
+
You can now use this package in any Node.js project without extra configuration.
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
Modern (ES Modules)
|
|
26
|
+
import getDeviceIP from 'get-device-ip';
|
|
24
27
|
|
|
28
|
+
const ip = getDeviceIP();
|
|
29
|
+
console.log('Primary IPv4:', ip.primaryIpv4);
|
|
25
30
|
|
|
31
|
+
Legacy (CommonJS)
|
|
32
|
+
const getDeviceIP = require('get-device-ip');
|
|
26
33
|
|
|
27
|
-
import getDeviceIP from 'get-device-ip';
|
|
28
34
|
const ip = getDeviceIP();
|
|
35
|
+
console.log('Primary IPv4:', ip.primaryIpv4);
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
📊 Return Object Structure
|
|
41
|
+
Calling getDeviceIP() returns a clean object:
|
|
29
42
|
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
Property,Type,Description
|
|
44
|
+
primaryIpv4,string,The first active local IPv4 address found.
|
|
45
|
+
primaryIpv6,string,The first active local IPv6 address found.
|
|
46
|
+
IPv4,string[],Array of all detected IPv4 addresses.
|
|
47
|
+
IPv6,string[],Array of all detected IPv6 addresses.
|
|
32
48
|
|
|
33
49
|
```
|
|
50
|
+
|
|
51
|
+
📄 License
|
|
52
|
+
MIT © Sakib Fakir
|
package/dist/script.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// script.js
|
|
30
|
+
var script_exports = {};
|
|
31
|
+
__export(script_exports, {
|
|
32
|
+
default: () => script_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(script_exports);
|
|
35
|
+
var import_os = __toESM(require("os"));
|
|
36
|
+
var getDeviceIP = () => {
|
|
37
|
+
const IPv4 = [];
|
|
38
|
+
const IPv6 = [];
|
|
39
|
+
try {
|
|
40
|
+
const deviceInfo = import_os.default.networkInterfaces();
|
|
41
|
+
for (const interfaceName in deviceInfo) {
|
|
42
|
+
deviceInfo[interfaceName].forEach((addr) => {
|
|
43
|
+
if (addr.internal) return;
|
|
44
|
+
if (addr.family === "IPv4" || addr.family === 4) {
|
|
45
|
+
IPv4.push(addr.address);
|
|
46
|
+
} else if (addr.family === "IPv6" || addr.family === 6) {
|
|
47
|
+
IPv6.push(addr.address);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
IPv4,
|
|
53
|
+
IPv6,
|
|
54
|
+
primaryIpv4: IPv4[0] || null,
|
|
55
|
+
primaryIpv6: IPv6[0] || null
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return { error: error.message, IPv4: [], IPv6: [] };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var script_default = getDeviceIP;
|
package/dist/script.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// script.js
|
|
2
|
+
import os from "os";
|
|
3
|
+
var getDeviceIP = () => {
|
|
4
|
+
const IPv4 = [];
|
|
5
|
+
const IPv6 = [];
|
|
6
|
+
try {
|
|
7
|
+
const deviceInfo = os.networkInterfaces();
|
|
8
|
+
for (const interfaceName in deviceInfo) {
|
|
9
|
+
deviceInfo[interfaceName].forEach((addr) => {
|
|
10
|
+
if (addr.internal) return;
|
|
11
|
+
if (addr.family === "IPv4" || addr.family === 4) {
|
|
12
|
+
IPv4.push(addr.address);
|
|
13
|
+
} else if (addr.family === "IPv6" || addr.family === 6) {
|
|
14
|
+
IPv6.push(addr.address);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
IPv4,
|
|
20
|
+
IPv6,
|
|
21
|
+
primaryIpv4: IPv4[0] || null,
|
|
22
|
+
primaryIpv6: IPv6[0] || null
|
|
23
|
+
};
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return { error: error.message, IPv4: [], IPv6: [] };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var script_default = getDeviceIP;
|
|
29
|
+
export {
|
|
30
|
+
script_default as default
|
|
31
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "get-device-ip",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A lightweight utility to get local IPv4 and IPv6 addresses.",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
5
|
+
"main": "./dist/script.cjs",
|
|
6
|
+
"module": "./dist/script.js",
|
|
7
7
|
"exports": {
|
|
8
|
-
".":
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/script.js",
|
|
10
|
+
"require": "./dist/script.cjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup script.js --format cjs,esm --clean",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
9
16
|
},
|
|
10
17
|
"author": "Sakib Fakir",
|
|
11
18
|
"license": "MIT",
|
|
@@ -19,5 +26,12 @@
|
|
|
19
26
|
"local-ip",
|
|
20
27
|
"device-ip",
|
|
21
28
|
"network"
|
|
29
|
+
],
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"tsup": "^8.5.1",
|
|
32
|
+
"typescript": "^5.9.3"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
22
36
|
]
|
|
23
37
|
}
|
package/script.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import os from 'os';
|
|
2
|
-
// Sakib Fakir
|
|
3
|
-
// published : 1/31/2026
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const getDeviceIP = () => {
|
|
7
|
-
const IPv4 = [];
|
|
8
|
-
const IPv6 = [];
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const deviceInfo = os.networkInterfaces();
|
|
12
|
-
|
|
13
|
-
for (const interfaceName in deviceInfo) {
|
|
14
|
-
deviceInfo[interfaceName].forEach((addr) => {
|
|
15
|
-
// Skip internal (loopback) addresses
|
|
16
|
-
if (addr.internal) return;
|
|
17
|
-
|
|
18
|
-
// Check for IPv4 (supports string 'IPv4' or number 4)
|
|
19
|
-
if (addr.family === 'IPv4' || addr.family === 4) {
|
|
20
|
-
IPv4.push(addr.address);
|
|
21
|
-
}
|
|
22
|
-
// Check for IPv6 (supports string 'IPv6' or number 6)
|
|
23
|
-
else if (addr.family === 'IPv6' || addr.family === 6) {
|
|
24
|
-
IPv6.push(addr.address);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
IPv4,
|
|
31
|
-
IPv6,
|
|
32
|
-
primaryIpv4: IPv4[0] || null,
|
|
33
|
-
primaryIpv6: IPv6[0] || null
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
} catch (error) {
|
|
37
|
-
|
|
38
|
-
return { error: error.message, IPv4: [], IPv6: [] };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default getDeviceIP;
|