當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。