n8n-nodes-my-local-ip
Version:
My Local Ip
167 lines • 6.82 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MyLocalIp = void 0;
const MyLocalIpResult_1 = require("./models/MyLocalIpResult");
const os = __importStar(require("node:os"));
const ip_1 = __importDefault(require("ip"));
class MyLocalIp {
constructor() {
this.description = {
displayName: 'My Local Ip',
name: 'myLocalIp',
icon: 'file:MyLocalIpLogo.svg',
group: ['output'],
version: 1,
triggerPanel: false,
subtitle: '={{$parameter["operation"]}}',
description: 'Get my local IP address',
defaults: {
name: 'My Local Ip',
},
inputs: ["main"],
outputs: ["main"],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Get My Local IP',
value: 'local_ip',
description: 'Get my local IP address',
action: 'Get my local IP',
},
],
default: 'local_ip',
},
{
displayName: 'Network Interface',
name: 'network_interface',
type: 'string',
default: '',
description: 'Define the network interface',
},
{
displayName: 'Version',
name: 'version',
type: 'options',
required: true,
options: [
{
name: 'IP V4',
value: 'local_ipv4',
action: 'Get my local ipv4',
},
{
name: 'IP V6',
value: 'local_ipv6',
action: 'Get my local ipv6',
},
{
name: 'Both IP V4/V6',
value: 'both_ipv4/6',
action: 'Get my local ipv4/ipv6',
},
],
default: 'local_ipv4',
},
{
displayName: 'Only External IP',
name: 'only_external_ip',
type: 'boolean',
default: false,
description: 'Get only external IP address',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [
{
displayName: 'Put Result in Field',
name: 'result_field',
type: 'string',
default: 'local',
description: 'The name of the output field to put the data in',
},
],
},
],
};
}
async execute() {
const items = this.getInputData();
const network_interface = this.getNodeParameter('network_interface', 0);
const version = this.getNodeParameter('version', 0);
const only_external_ip = this.getNodeParameter('only_external_ip', 0);
const options = this.getNodeParameter('options', 0);
const result_field = options.result_field ? options.result_field : 'local';
const interfaces = os.networkInterfaces();
const result = new MyLocalIpResult_1.MyLocalIpResult();
for (const interfaceName in interfaces) {
for (const iface of interfaces[interfaceName]) {
if (network_interface == '' || network_interface == interfaceName) {
if (!only_external_ip || (only_external_ip && !iface.internal)) {
if (version == 'both_ipv4/6' ||
(version == 'local_ipv4' && iface.family == 'IPv4') ||
(version == 'local_ipv6' && iface.family == 'IPv6')) {
result.interfaces.push({
hostname: os.hostname(),
family: iface.family,
interface: interfaceName,
address: iface.address,
mac: iface.mac,
internal: iface.internal,
subnet: ip_1.default.subnet(iface.address, iface.netmask),
});
}
}
}
}
}
items.forEach((item) => (item.json[result_field] = result));
return [items];
}
}
exports.MyLocalIp = MyLocalIp;
//# sourceMappingURL=MyLocalIp.node.js.map