本文整理汇总了TypeScript中ip.fromLong函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromLong函数的具体用法?TypeScript fromLong怎么用?TypeScript fromLong使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromLong函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: handleSocks4FinalHandshakeResponse
/**
* Handles Socks v4 handshake response.
* @param data
*/
private handleSocks4FinalHandshakeResponse() {
const data = this._receiveBuffer.get(8);
if (data[1] !== Socks4Response.Granted) {
this._closeSocket(
`${ERRORS.Socks4ProxyRejectedConnection} - (${Socks4Response[data[1]]})`
);
} else {
// Bind response
if (SocksCommand[this._options.command] === SocksCommand.bind) {
const buff = SmartBuffer.fromBuffer(data);
buff.readOffset = 2;
const remoteHost: SocksRemoteHost = {
port: buff.readUInt16BE(),
host: ip.fromLong(buff.readUInt32BE())
};
// If host is 0.0.0.0, set to proxy host.
if (remoteHost.host === '0.0.0.0') {
remoteHost.host = this._options.proxy.ipaddress;
}
this.state = SocksClientState.BoundWaitingForConnection;
this.emit('bound', { socket: this._socket, remoteHost });
// Connect response
} else {
this.state = SocksClientState.Established;
this.removeInternalSocketHandlers();
this.emit('established', { socket: this._socket });
}
}
}
开发者ID:JoshGlazebrook,项目名称:socks,代码行数:37,代码来源:socksclient.ts
示例2: parseUDPFrame
/**
* Parses a SOCKS UDP frame.
* @param data
*/
static parseUDPFrame(data: Buffer): SocksUDPFrameDetails {
const buff = SmartBuffer.fromBuffer(data);
buff.readOffset = 2;
const frameNumber = buff.readUInt8();
const hostType: Socks5HostType = buff.readUInt8();
let remoteHost;
if (hostType === Socks5HostType.IPv4) {
remoteHost = ip.fromLong(buff.readUInt32BE());
} else if (hostType === Socks5HostType.IPv6) {
remoteHost = ip.toString(buff.readBuffer(16));
} else {
remoteHost = buff.readString(buff.readUInt8());
}
const remotePort = buff.readUInt16BE();
return {
frameNumber,
remoteHost: {
host: remoteHost,
port: remotePort
},
data: buff.readBuffer()
};
}
开发者ID:JoshGlazebrook,项目名称:socks,代码行数:31,代码来源:socksclient.ts
示例3: handleSocks4IncomingConnectionResponse
/**
* Handles Socks v4 incoming connection request (BIND)
* @param data
*/
private handleSocks4IncomingConnectionResponse() {
const data = this._receiveBuffer.get(8);
if (data[1] !== Socks4Response.Granted) {
this._closeSocket(
`${ERRORS.Socks4ProxyRejectedIncomingBoundConnection} - (${
Socks4Response[data[1]]
})`
);
} else {
const buff = SmartBuffer.fromBuffer(data);
buff.readOffset = 2;
const remoteHost: SocksRemoteHost = {
port: buff.readUInt16BE(),
host: ip.fromLong(buff.readUInt32BE())
};
this.state = SocksClientState.Established;
this.removeInternalSocketHandlers();
this.emit('established', { socket: this._socket, remoteHost });
}
}
开发者ID:JoshGlazebrook,项目名称:socks,代码行数:27,代码来源:socksclient.ts
示例4: fromLong
static fromLong(address: number) {
return fromLong(address);
}
开发者ID:no0dles,项目名称:janner,代码行数:3,代码来源:util.ts
示例5: handleSocks5IncomingConnectionResponse
/**
* Handles Socks v5 incoming connection request (BIND).
*/
private handleSocks5IncomingConnectionResponse() {
// Peek at available data (we need at least 5 bytes to get the hostname length)
const header = this._receiveBuffer.peek(5);
if (header[0] !== 0x05 || header[1] !== Socks5Response.Granted) {
this._closeSocket(
`${ERRORS.Socks5ProxyRejectedIncomingBoundConnection} - ${
Socks5Response[header[1]]
}`
);
} else {
// Read address type
const addressType = header[3];
let remoteHost: SocksRemoteHost;
let buff: SmartBuffer;
// IPv4
if (addressType === Socks5HostType.IPv4) {
// Check if data is available.
const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv4;
if (this._receiveBuffer.length < dataNeeded) {
this._nextRequiredPacketBufferSize = dataNeeded;
return;
}
buff = SmartBuffer.fromBuffer(
this._receiveBuffer.get(dataNeeded).slice(4)
);
remoteHost = {
host: ip.fromLong(buff.readUInt32BE()),
port: buff.readUInt16BE()
};
// If given host is 0.0.0.0, assume remote proxy ip instead.
if (remoteHost.host === '0.0.0.0') {
remoteHost.host = this._options.proxy.ipaddress;
}
// Hostname
} else if (addressType === Socks5HostType.Hostname) {
const hostLength = header[4];
const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHostname(
hostLength
); // header + host length + port
// Check if data is available.
if (this._receiveBuffer.length < dataNeeded) {
this._nextRequiredPacketBufferSize = dataNeeded;
return;
}
buff = SmartBuffer.fromBuffer(
this._receiveBuffer.get(dataNeeded).slice(5) // Slice at 5 to skip host length
);
remoteHost = {
host: buff.readString(hostLength),
port: buff.readUInt16BE()
};
// IPv6
} else if (addressType === Socks5HostType.IPv6) {
// Check if data is available.
const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;
if (this._receiveBuffer.length < dataNeeded) {
this._nextRequiredPacketBufferSize = dataNeeded;
return;
}
buff = SmartBuffer.fromBuffer(
this._receiveBuffer.get(dataNeeded).slice(4)
);
remoteHost = {
host: ip.toString(buff.readBuffer(16)),
port: buff.readUInt16BE()
};
}
this.state = SocksClientState.Established;
this.removeInternalSocketHandlers();
this.emit('established', { socket: this._socket, remoteHost });
}
}
开发者ID:JoshGlazebrook,项目名称:socks,代码行数:88,代码来源:socksclient.ts
示例6: handleSocks5FinalHandshakeResponse
/**
* Handles Socks v5 final handshake response.
* @param data
*/
private handleSocks5FinalHandshakeResponse() {
// Peek at available data (we need at least 5 bytes to get the hostname length)
const header = this._receiveBuffer.peek(5);
if (header[0] !== 0x05 || header[1] !== Socks5Response.Granted) {
this._closeSocket(
`${ERRORS.InvalidSocks5FinalHandshakeRejected} - ${
Socks5Response[header[1]]
}`
);
} else {
// Read address type
const addressType = header[3];
let remoteHost: SocksRemoteHost;
let buff: SmartBuffer;
// IPv4
if (addressType === Socks5HostType.IPv4) {
// Check if data is available.
const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv4;
if (this._receiveBuffer.length < dataNeeded) {
this._nextRequiredPacketBufferSize = dataNeeded;
return;
}
buff = SmartBuffer.fromBuffer(
this._receiveBuffer.get(dataNeeded).slice(4)
);
remoteHost = {
host: ip.fromLong(buff.readUInt32BE()),
port: buff.readUInt16BE()
};
// If given host is 0.0.0.0, assume remote proxy ip instead.
if (remoteHost.host === '0.0.0.0') {
remoteHost.host = this._options.proxy.ipaddress;
}
// Hostname
} else if (addressType === Socks5HostType.Hostname) {
const hostLength = header[4];
const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHostname(
hostLength
); // header + host length + host + port
// Check if data is available.
if (this._receiveBuffer.length < dataNeeded) {
this._nextRequiredPacketBufferSize = dataNeeded;
return;
}
buff = SmartBuffer.fromBuffer(
this._receiveBuffer.get(dataNeeded).slice(5) // Slice at 5 to skip host length
);
remoteHost = {
host: buff.readString(hostLength),
port: buff.readUInt16BE()
};
// IPv6
} else if (addressType === Socks5HostType.IPv6) {
// Check if data is available.
const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;
if (this._receiveBuffer.length < dataNeeded) {
this._nextRequiredPacketBufferSize = dataNeeded;
return;
}
buff = SmartBuffer.fromBuffer(
this._receiveBuffer.get(dataNeeded).slice(4)
);
remoteHost = {
host: ip.toString(buff.readBuffer(16)),
port: buff.readUInt16BE()
};
}
// We have everything we need
this.state = SocksClientState.ReceivedFinalResponse;
// If using CONNECT, the client is now in the established state.
if (SocksCommand[this._options.command] === SocksCommand.connect) {
this.state = SocksClientState.Established;
this.removeInternalSocketHandlers();
this.emit('established', { socket: this._socket });
} else if (SocksCommand[this._options.command] === SocksCommand.bind) {
/* If using BIND, the Socks client is now in BoundWaitingForConnection state.
This means that the remote proxy server is waiting for a remote connection to the bound port. */
this.state = SocksClientState.BoundWaitingForConnection;
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader;
this.emit('bound', { socket: this._socket, remoteHost });
/*
//.........这里部分代码省略.........
开发者ID:JoshGlazebrook,项目名称:socks,代码行数:101,代码来源:socksclient.ts
注:本文中的ip.fromLong函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论