"use strict";
/**
 * penguins-eggs
 * class: network.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const netmask_1 = require("netmask");
const os_1 = tslib_1.__importDefault(require("os"));
/**
 *
 */
class Network {
    /**
     *
     */
    constructor() {
        this.address = '';
        this.cidr = '';
        this.family = '';
        this.internal = false;
        this.mac = '';
        this.netmask = '';
        this.o = {};
        const interfaces = os_1.default.networkInterfaces();
        const address = '';
        if (interfaces !== undefined) {
            for (const devName in interfaces) {
                const iface = interfaces[devName];
                if (iface !== undefined) {
                    for (const alias of iface) {
                        if (alias.family === 'IPv4' &&
                            alias.address !== '127.0.0.1' &&
                            !alias.internal) {
                            // take just the first!
                            if (this.address === '') {
                                this.address = alias.address;
                            }
                            if (this.cidr === '' && alias.cidr !== null) {
                                this.cidr = alias.cidr;
                            }
                            if (this.family === '') {
                                this.family = alias.family;
                            }
                            if (this.mac === '') {
                                this.mac = alias.mac;
                            }
                            if (this.netmask === '') {
                                this.netmask = alias.netmask;
                            }
                        }
                    }
                }
            }
            /**
                 * valori da netmask
                 */
            this.o = new netmask_1.Netmask(this.cidr);
        }
    }
    base() {
        return this.o.base;
    }
    broadcast() {
        return this.o.broadcast;
    }
    bitmask() {
        this.o.bitmask;
    }
    contains() {
        return this.o.contains;
    }
    first() {
        return this.o.first;
    }
    forEach() {
        return this.o.forEach;
    }
    hostmask() {
        return this.o.hostmask;
    }
    last() {
        return this.o.last;
    }
    maskLong() {
        return this.o.maskLong;
    }
    netLong() {
        return this.o.netLong;
    }
    next() {
        return this.o.next;
    }
    size() {
        return this.o.size;
    }
    toString() {
        return this.o.toString;
    }
}
exports.default = Network;
