当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript dns.lookup函数代码示例

本文整理汇总了TypeScript中dns.lookup函数的典型用法代码示例。如果您正苦于以下问题:TypeScript lookup函数的具体用法?TypeScript lookup怎么用?TypeScript lookup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了lookup函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: reject

 new Promise<string>((fulfill, reject) => {
   dns.lookup(hostname, 4, (e, address) => {
     if (e) {
       return reject(new errors.ServerUnreachable('could not resolve proxy server hostname'));
     }
     fulfill(address);
   });
 }),
开发者ID:hlyu368,项目名称:outline-client,代码行数:8,代码来源:connectivity.ts

示例2: fqdn

function fqdn(callback: (err: Error | null, fqdn?: string) => void) {

    const uqdn = os.hostname();

    dns.lookup(uqdn, { hints: dns.ADDRCONFIG }, (err1: Error | null, ip: string) => {
        if (err1) {
            return callback(err1);
        }

        dns.lookupService(ip, 0, (err2: Error | null, _fqdn: string) => {

            if (err2) {
                return callback(err2);
            }
            _fqdn = _fqdn.replace(".localdomain", "");
            callback(null, _fqdn);
        });
    });
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:19,代码来源:hostname.ts

示例3:

namespace net_tests {
    {
        // Make sure .listen() and .close() retuern a Server instance
        net.createServer().listen(0).close().address();
    }
}

///////////////////////////////////////////////////
/// DNS Tests : https://nodejs.org/api/dns.html ///
///////////////////////////////////////////////////

namespace dns_tests {
    dns.lookup("nodejs.org", (err, address, family) => {
        const _err: NodeJS.ErrnoException = err;
        const _address: string = address;
        const _family: number = family;
    });
    dns.lookup("nodejs.org", 4, (err, address, family) => {
        const _err: NodeJS.ErrnoException = err;
        const _address: string = address;
        const _family: number = family;
    });
    dns.lookup("nodejs.org", 6, (err, address, family) => {
        const _err: NodeJS.ErrnoException = err;
        const _address: string = address;
        const _family: number = family;
    });
    dns.lookup("nodejs.org", {}, (err, address, family) => {
        const _err: NodeJS.ErrnoException = err;
        const _address: string = address;
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:30,代码来源:node-tests.ts

示例4: lookup

export const networkEnabled: Promise<boolean> = new Promise<boolean>((r, j) => {
  lookup("8.8.8.8", 4, (err, address, family) => {
    r(err ? false : true);
  });
});
开发者ID:indrajithbandara,项目名称:autorest,代码行数:5,代码来源:autorest-as-a-service.ts

示例5: Promise

 return new Promise(resolve => {
   dns.lookup('registry.yarnpkg.com', err => {
     resolve(err === null)
   })
 })
开发者ID:aranja,项目名称:tux,代码行数:5,代码来源:new.ts

示例6: getRelayCell

    /**
     * Returns a cell of type RELAY. Appropriate body members can be stored in "extras", where they will be safely added to the cell.
     * @param {number} the circuit ID
     * @param {number} the stream ID
     * @param {number} the digest
     * @param {RelayCommand} the relay command
     * @param {any} extras - a JSON object containing anything to be put in
     *  the body. The valid keys for this object are "host", "agentID", and
     *  "data".
     * @param {Function} callback
     */
    public getRelayCell(circuitID : number, streamID : number, cmd : RelayCommand, extras : any, callback : Function) {
        var buf : Buffer = new Buffer(Constant.CELL_SIZE);
        buf.writeUInt16BE(circuitID, 0);
        buf.writeUInt8(CellType.RELAY, 2);
        buf.writeUInt16BE(streamID, 3);
        buf.writeUInt16BE(0, 5);
        buf.writeUInt32BE(0, 7);
        buf.writeUInt8(cmd, 13);

        // process the aditional parameters
        switch (cmd) {
            case RelayCommand.BEGIN:
                var host : string = extras["host"];
                if (typeof(host) == "undefined" || host.indexOf(':') == -1) {
                    this.aEmit('error', ErrorType.CELL_FORMAT, "RELAY->BEGIN cell creation: host is undefined");
                    callback(null);
                    return;
                }
                var hostname = host.split(':')[0];
                var port = host.split(':')[1];

                if (!this.checkIsIP(hostname)) {
                    dns.lookup(hostname, 4, ((err, address) => {
                        var finalAddress = address + ':' + port;
                        buf.writeUInt16BE(finalAddress.length + 1, 11);
                        buf.write(finalAddress, Constant.RELAY_HEADER_SIZE, finalAddress.length, 'ascii');
                        // write the null terminator
                        buf.writeUInt8(0, Constant.RELAY_HEADER_SIZE + finalAddress.length);
                        callback(buf);
                    }));

                    return;
                } else {
                    var finalAddress = host;
                    buf.writeUInt16BE(finalAddress.length + 1, 11);
                    buf.write(finalAddress, Constant.RELAY_HEADER_SIZE, finalAddress.length, 'ascii');
                    // write the null terminator
                    buf.writeUInt8(0, Constant.RELAY_HEADER_SIZE + finalAddress.length);
                }

                break;
            case RelayCommand.DATA:
                var data : Buffer = extras["data"];
                if (typeof(data) == "undefined") {
                    this.aEmit('error', ErrorType.CELL_FORMAT, "RELAY->DATA cell creation: Data is undefined");
                    callback(null);
                    return;
                } else if (data.length > Constant.CELL_SIZE - Constant.RELAY_HEADER_SIZE) {
                    this.aEmit('error', ErrorType.CELL_SIZE, "RELAY->DATA cell creation: Data too long for cell");
                    callback(null);
                    return;
                }
                buf.writeUInt16BE(data.length, 11);
                data.copy(buf, Constant.RELAY_HEADER_SIZE, 0, data.length);
                break;
            case RelayCommand.EXTEND:
                var host : string = extras["host"];
                var agentID : number = extras["agentID"];
                if (typeof(host) == "undefined") {
                    this.aEmit('error', ErrorType.CELL_FORMAT, "RELAY->EXTEND cell creation: host is undefined");
                    callback(null);
                    return;
                } else if (typeof(agentID) == "undefined") {
                    this.aEmit('error', ErrorType.CELL_FORMAT, "RELAY->EXTEND cell creation: agentID is undefined");
                    callback(null);
                    return;
                }
                buf.write(host, Constant.RELAY_HEADER_SIZE, host.length, 'ascii');
                buf.writeUInt8(0, Constant.RELAY_HEADER_SIZE + host.length);
                buf.writeUInt32BE(agentID, Constant.RELAY_HEADER_SIZE + host.length + 1);
                buf.writeUInt16BE(host.length + 5, 11);
                break;
            default:
                buf.writeUInt16BE(0, 11);
                break;
        }
        callback(buf);
    }
开发者ID:aaronnech,项目名称:SimpleTorRouter,代码行数:89,代码来源:Tor61CellService.ts

示例7: lookup

 return new Promise<string>((resolve, error) => {
     lookup(hostname(), (err, add, fam) => {
         resolve(add);
     });
 });
开发者ID:shaddockh,项目名称:audiobook_to_podcast_gen,代码行数:5,代码来源:buildPodcast.ts


注:本文中的dns.lookup函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。