• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript net.isIP函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript net.Server类代码示例发布时间:2022-05-25
下一篇:
TypeScript net.createServer函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap