當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript net.isIP函數代碼示例

本文整理匯總了TypeScript中net.isIP函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isIP函數的具體用法?TypeScript isIP怎麽用?TypeScript isIP使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isIP函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: ExpectedError

export const ip: ValidatorFunction<string> = (value, {name}) => {
  if (!Net.isIP(value)) {
    throw new ExpectedError(
      `Value (${value}) of "${name}" is not a valid IP address`,
    );
  }
};
開發者ID:vilic,項目名稱:clime,代碼行數:7,代碼來源:network.ts

示例2: resolve

 .on('end', () => {
   const ip = Buffer.concat(data).toString()
   if (isIP(ip)) {
     resolve(ip)
   } else {
     reject(new TypeError('Invalid IP address:' + ip))
   }
 })
開發者ID:wenwei1202,項目名稱:dnspod-ddns,代碼行數:8,代碼來源:util.ts

示例3: addTimeout

	request.once('socket', (socket: net.Socket): void => {
		const {socketPath} = request as any;

		/* istanbul ignore next: hard to test */
		if (socket.connecting) {
			if (delays.lookup !== undefined && !socketPath && !net.isIP(hostname || host)) {
				const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
				socket.once('lookup', cancelTimeout);
			}

			if (delays.connect !== undefined) {
				const timeConnect = () => addTimeout(delays.connect!, timeoutHandler, 'connect');

				if (socketPath || net.isIP(hostname || host)) {
					socket.once('connect', timeConnect());
				} else {
					socket.once('lookup', (error: Error): void => {
						if (error === null) {
							socket.once('connect', timeConnect());
						}
					});
				}
			}

			if (delays.secureConnect !== undefined && options.protocol === 'https:') {
				socket.once('connect', (): void => {
					const cancelTimeout = addTimeout(delays.secureConnect!, timeoutHandler, 'secureConnect');
					socket.once('secureConnect', cancelTimeout);
				});
			}
		}

		if (delays.send !== undefined) {
			const timeRequest = () => addTimeout(delays.send!, timeoutHandler, 'send');
			/* istanbul ignore next: hard to test */
			if (socket.connecting) {
				socket.once('connect', (): void => {
					request.once('upload-complete', timeRequest());
				});
			} else {
				request.once('upload-complete', timeRequest());
			}
		}
	});
開發者ID:sindresorhus,項目名稱:got,代碼行數:44,代碼來源:timed-out.ts

示例4: udpAssociate

 udpAssociate(client: net.Socket, udpServer: { addr: string, port: number }, cipherAlgorithm: string, password: string) {
   let udpType = 'udp' + (net.isIP(udpServer.addr) || 4);
   let listeningUdp = dgram.createSocket(udpType);
   
   listeningUdp.bind();
   listeningUdp.unref();
   listeningUdp.once('listening', async () => {
     let udpAddr = listeningUdp.address();
     let reply = socks5Helper.createSocks5TcpReply(0x0, udpAddr.family === 'IPv4' ? ATYP.IPV4 : ATYP.IPV6, udpAddr.address, udpAddr.port);
     await client.writeAsync(reply);
   });
   
   let udpSet = new Set<dgram.Socket>();
   listeningUdp.on('message', async (msg: Buffer, cinfo: dgram.RemoteInfo) => {
     let proxyUdp = dgram.createSocket(udpType);
     proxyUdp.unref();
     
     let encryptor = cryptoEx.createCipher(cipherAlgorithm, password);
     let cipher = encryptor.cipher;
     let iv = encryptor.iv;
     let decipher = cryptoEx.createDecipher(cipherAlgorithm, password, iv);
     
     let pl = Number((Math.random() * 0xff).toFixed());
     let el = new Buffer([pl]);
     let rp = crypto.randomBytes(pl);
     let em = cipher.update(Buffer.concat([el, rp, msg]));
     
     let data = Buffer.concat([iv, em]);
     proxyUdp.send(data, 0, data.length, udpServer.port, udpServer.addr);
     
     proxyUdp.on('message', (sMsg: Buffer, sinfo: dgram.RemoteInfo) => {
       let reply = decipher.update(sMsg);
       let header = socks5Helper.createSocks5UdpHeader(cinfo.address, cinfo.port);
       let data = Buffer.concat([header, reply]);
       listeningUdp.send(data, 0, data.length, cinfo.port, cinfo.address);
     });
     
     proxyUdp.on('error', (err) => console.log(err.message));
     udpSet.add(proxyUdp);
   });
   
   function dispose() {
     listeningUdp.removeAllListeners();
     listeningUdp.close();
     listeningUdp.unref();
     
     udpSet.forEach(udp => {
       udp.close();
     });
   }
   
   client.once('error', dispose);
   client.once('end', dispose);
   listeningUdp.on('error', dispose);
   listeningUdp.on('close', dispose);
 }
開發者ID:52M,項目名稱:LightSword,代碼行數:56,代碼來源:remoteProxyServer.ts

示例5: subdomains

    get subdomains() {
        var hostname = this.hostname;

        if (!hostname) return [];

        var subdomains = !isIP(hostname)
            ? hostname.split('.').reverse()
            : [hostname];

        return subdomains;
    }
開發者ID:yogendrap,項目名稱:PlZoo,代碼行數:11,代碼來源:Request.ts

示例6: udpAssociate

  static udpAssociate(client: net.Socket, dst: { port: number, addr: string }) {
    let udpType = 'udp' + (net.isIP(dst.addr) || 4);
    let serverUdp = dgram.createSocket(udpType);
    serverUdp.bind();
    serverUdp.unref();
    serverUdp.on('listening', async () => {
      let udpAddr = serverUdp.address();
      let reply = socks5Helper.createSocks5TcpReply(0x0, udpAddr.family === 'IPv4' ? ATYP.IPV4 : ATYP.IPV6, udpAddr.address, udpAddr.port);
      await client.writeAsync(reply);
    });
    
    let udpSet = new Set<dgram.Socket>();
    serverUdp.on('message', (msg: Buffer, rinfo: dgram.RemoteInfo) => {
      let socketId = `${rinfo.address}:${rinfo.port}`;
      let dst = socks5Helper.refineDestination(msg);
      
      let proxyUdp = dgram.createSocket(udpType);
      proxyUdp.unref();
      
      proxyUdp.on('message', (msg: Buffer) => {
        let header = socks5Helper.createSocks5UdpHeader(rinfo.address, rinfo.port);
        let data = Buffer.concat([header, msg]);
        serverUdp.send(data, 0, data.length, rinfo.port, rinfo.address);
      });
      
      proxyUdp.on('error', (err) => console.log(err.message));

      proxyUdp.send(msg, dst.headerSize, msg.length - dst.headerSize, dst.port, dst.addr);
      udpSet.add(proxyUdp);
    });
    
    function dispose() {
      client.dispose();
      
      serverUdp.removeAllListeners();
      serverUdp.close();
      
      udpSet.forEach(udp => {
        udp.close();
        udp.removeAllListeners();
      });
      
      udpSet.clear();
    }
    
    serverUdp.on('error', dispose);
    client.on('error', dispose);
    client.on('end', dispose);
  }
開發者ID:52M,項目名稱:LightSword,代碼行數:49,代碼來源:localProxyServer.ts

示例7: parseAddrToBytes

function parseAddrToBytes(fullAddr: string): { addrBytes: number[], type: ATYP } {
  let type = net.isIP(fullAddr);
  let addrBytes = [];
  switch (type) {
    case 4:
      addrBytes = fullAddr.split('.').select(s => Number.parseInt(s)).toArray();
      break;
    case 6:
      addrBytes = fullAddr.split(':').select(s => [Number.parseInt(s.substr(0, 2), 16), Number.parseInt(s.substr(2, 2), 16)]).aggregate((c: Array<number>, n) => c.concat(n));
      break;
    case 0:
      fullAddr.each((c, i) => addrBytes.push(fullAddr.charCodeAt(i)));
      break;
  }
  
  return { addrBytes, type: type ? (type === 4 ? ATYP.IPV4 : ATYP.IPV6) : ATYP.DN }
}
開發者ID:52M,項目名稱:LightSword,代碼行數:17,代碼來源:socks5helper.ts

示例8: async

 socks.createConnection(clientOpts, async (err, socket, info) => {
   if (err) return assert.fail(err, null, err.message);
   assert(net.isIP(socket.remoteAddress));
   done();
 });
開發者ID:Amonhuz,項目名稱:LightSword,代碼行數:5,代碼來源:socks5.ts

示例9: udpAssociate

export function udpAssociate(client: net.Socket, rawData: Buffer, dst: { addr: string, port: number }, options: HandshakeOptions) {
  let udpType = 'udp' + (net.isIP(dst.addr) || 4);
  let serverUdp = dgram.createSocket(udpType);
  let ivLength: number = cryptoEx.SupportedCiphers[options.cipherAlgorithm][1];
  
  serverUdp.bind();
  serverUdp.unref();
  serverUdp.once('listening', async () => {
    let udpAddr = serverUdp.address();
    let reply = socksHelper.createSocks5TcpReply(0x0, udpAddr.family === 'IPv4' ? ATYP.IPV4 : ATYP.IPV6, udpAddr.address, udpAddr.port);
    
    let encryptor = cryptoEx.createCipher(options.cipherAlgorithm, options.password);
    let cipher = encryptor.cipher;
    let iv = encryptor.iv;
    
    let pl = Number((Math.random() * 0xff).toFixed());
    let el = new Buffer([pl]);
    let pd = crypto.randomBytes(pl);
    let er = cipher.update(Buffer.concat([el, pd, reply]));
    
    await client.writeAsync(Buffer.concat([iv, er]));
  });
  
  let udpSet = new Set<dgram.Socket>();
  serverUdp.on('message', async (msg: Buffer, cinfo: dgram.RemoteInfo) => {
    let iv = new Buffer(ivLength);
    msg.copy(iv, 0, 0, ivLength);
    
    let decipher = cryptoEx.createDecipher(options.cipherAlgorithm, options.password, iv);
    let cipher = cryptoEx.createCipher(options.cipherAlgorithm, options.password, iv).cipher;
    
    let data = decipher.update(msg.slice(iv.length, msg.length));
    let pl = data[0];
    
    let udpMsg = data.slice(1 + pl, data.length);
    let dst = socksHelper.refineDestination(udpMsg);
    
    let socketId = `${cinfo.address}:${cinfo.port}`;
    let proxyUdp = dgram.createSocket(udpType);
    proxyUdp.unref();
    
    proxyUdp.send(udpMsg, dst.headerSize, udpMsg.length - dst.headerSize, dst.port, dst.addr);
    proxyUdp.on('message', (msg: Buffer, rinfo: dgram.RemoteInfo) => {
      let data = cipher.update(msg);
      proxyUdp.send(data, 0, data.length, cinfo.port, cinfo.address);
    });
    
    proxyUdp.on('error', (err: Error) => console.log(err.message));
    udpSet.add(proxyUdp);
  });
  
  function dispose() {
    serverUdp.removeAllListeners();
    serverUdp.close();
    serverUdp.unref();
    
    client.dispose();
    
    udpSet.forEach(udp => {
      udp.close();
    });
  }
  
  client.on('error', dispose);
  client.on('end', dispose);
  serverUdp.on('error', dispose);
  serverUdp.on('close', dispose);
}
開發者ID:52M,項目名稱:LightSword,代碼行數:68,代碼來源:udpHandler.ts

示例10:

const validate = (ip: string): boolean => {
  const version = net.isIP(ip);
  return version === 4 || version === 6;
};
開發者ID:runk,項目名稱:node-maxmind,代碼行數:4,代碼來源:ip.ts


注:本文中的net.isIP函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。