本文整理汇总了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`,
);
}
};
示例2: resolve
.on('end', () => {
const ip = Buffer.concat(data).toString()
if (isIP(ip)) {
resolve(ip)
} else {
reject(new TypeError('Invalid IP address:' + ip))
}
})
示例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());
}
}
});
示例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);
}
示例5: subdomains
get subdomains() {
var hostname = this.hostname;
if (!hostname) return [];
var subdomains = !isIP(hostname)
? hostname.split('.').reverse()
: [hostname];
return subdomains;
}
示例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);
}
示例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 }
}
示例8: async
socks.createConnection(clientOpts, async (err, socket, info) => {
if (err) return assert.fail(err, null, err.message);
assert(net.isIP(socket.remoteAddress));
done();
});
示例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);
}
示例10:
const validate = (ip: string): boolean => {
const version = net.isIP(ip);
return version === 4 || version === 6;
};