- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试弄清楚我收到了多少数据包以及它们代表什么时遇到了一些问题。
我正在尝试将一个数据包发送到一个 tor 节点并获得响应,我的想法是这是连接过程的开始,它将让我创建一个节点链来使用该服务。
我从这个文档中获取了我的数据包结构:
3. Cell Packet format
The basic unit of communication for onion routers and onion
proxies is a fixed-width "cell".
On a version 1 connection, each cell contains the following:
fields:
CircID [CIRCID_LEN bytes]
Command [1 byte]
Payload (padded with 0 bytes) [PAYLOAD_LEN bytes]
On a version 2 or higher connection, all cells are as in version 1
connections, except for variable-length cells, whose format is:
CircID [CIRCID_LEN octets]
Command [1 octet]
Length [2 octets; big-endian integer]
Payload [Length bytes]
On a version 2 connection, variable-length cells are indicated by a
command byte equal to 7 ("VERSIONS"). On a version 3 or
higher connection, variable-length cells are indicated by a command
byte equal to 7 ("VERSIONS"), or greater than or equal to 128.
CIRCID_LEN is 2 for link protocol versions 1, 2, and 3. CIRCID_LEN
is 4 for link protocol version 4 or higher. The VERSIONS cell itself
always has CIRCID_LEN == 2 for backward compatibility.
The CircID field determines which circuit, if any, the cell is
associated with.
The 'Command' field of a fixed-length cell holds one of the following
values:
0 -- PADDING (Padding) (See Sec 7.2)
1 -- CREATE (Create a circuit) (See Sec 5.1)
2 -- CREATED (Acknowledge create) (See Sec 5.1)
3 -- RELAY (End-to-end data) (See Sec 5.5 and 6)
4 -- DESTROY (Stop using a circuit) (See Sec 5.4)
5 -- CREATE_FAST (Create a circuit, no PK) (See Sec 5.1)
6 -- CREATED_FAST (Circuit created, no PK) (See Sec 5.1)
8 -- NETINFO (Time and address info) (See Sec 4.5)
9 -- RELAY_EARLY (End-to-end data; limited)(See Sec 5.6)
10 -- CREATE2 (Extended CREATE cell) (See Sec 5.1)
11 -- CREATED2 (Extended CREATED cell) (See Sec 5.1)
Variable-length command values are:
7 -- VERSIONS (Negotiate proto version) (See Sec 4)
128 -- VPADDING (Variable-length padding) (See Sec 7.2)
129 -- CERTS (Certificates) (See Sec 4.2)
130 -- AUTH_CHALLENGE (Challenge value) (See Sec 4.3)
131 -- AUTHENTICATE (Client authentication)(See Sec 4.5)
132 -- AUTHORIZE (Client authorization) (Not yet used)
The interpretation of 'Payload' depends on the type of the cell.
PADDING: Payload is unused.
CREATE: Payload contains the handshake challenge.
CREATED: Payload contains the handshake response.
RELAY: Payload contains the relay header and relay body.
DESTROY: Payload contains a reason for closing the circuit.
(see 5.4)
Upon receiving any other value for the command field, an OR must
drop the cell. Since more cell types may be added in the future, ORs
should generally not warn when encountering unrecognized commands.
The payload is padded with 0 bytes.
PADDING cells are currently used to implement connection keepalive.
If there is no other traffic, ORs and OPs send one another a PADDING
cell every few minutes.
CREATE, CREATED, and DESTROY cells are used to manage circuits;
see section 5 below.
RELAY cells are used to send commands and data along a circuit; see
section 6 below.
VERSIONS and NETINFO cells are used to set up connections in link
protocols v2 and higher; in link protocol v3 and higher, CERTS,
AUTH_CHALLENGE, and AUTHENTICATE may also be used. See section 4
below.
https://gitweb.torproject.org/torspec.git?a=blob_plain;hb=HEAD;f=tor-spec.txt
我已经成功地向一个节点发送了一个数据包:
import ssl
import socket
import struct
import binascii
s = socket.socket()
ssl_sock = ssl.wrap_socket(s)
ssl_sock.connect(("", 443))
pkt = struct.pack(">HBHH", 0, 7, 2, 3)
ssl_sock.send(pkt)
recv_pkt = ssl_sock.recv(1500)
print ":".join("{:02x}".format(ord(c)) for c in recv_pkt)
这向节点发送了一个数据包,我得到了以下信息:
00:00:07:00:04:00:03:00:04:00:00:81:03:88:02:01:01:be:30:82:01:ba:30:82:01:23:a0:03:02:01:02:02:08:78:ef:3f:c3:c7:b8:06:ad:30:0d:06:09:2a:86:48:86:f7:0d:01:01:05:05:00:30:22:31:20:30:1e:06:03:55:04:03:13:17:77:77:77:2e:6b:7a:6e:79:74:72:7a:62:33:6e:6d:6e:32:63:68:2e:63:6f:6d:30:1e:17:0d:31:34:30:33:33:31:30:30:30:30:30:30:5a:17:0d:31:35:30:33:30:34:32:33:35:39:35:39:5a:30:1d:31:1b:30:19:06:03:55:04:03:13:12:77:77:77:2e:78:79:32:71:69:75:70:72:34:74:2e:6e:65:74:30:81:9f:30:0d:06:09:2a:86:48:86:f7:0d:01:01:01:05:00:03:81:8d:00:30:81:89:02:81:81:00:d1:66:cd:6c:14:14:7b:ff:79:1a:5a:30:0e:2d:fd:d9:85:79:a9:38:5d:9e:c1:09:35:fb:59:c7:1f:5b:ab:cc:1d:65:03:ed:62:d1:58:38:a4:e3:35:97:da:29:04:41:1d:e0:fa:50:f5:48:ba:87:fc:b2:9a:b6:0e:93:b9:a3:2e:fa:13:d1:75:ae:51:0f:95:2c:9a:fc:fc:b8:77:49:19:2a:4e:cb:9d:61:e4:cf:ef:38:0c:1f:a7:91:fd:98:de:57:5c:0e:29:1d:d9:36:df:ac:17:0b:cb:a0:a2:02:29:93:8b:5f:48:66:95:56:b9:4d:c0:c0:77:41:9c:91:02:03:01:00:01:30:0d:06:09:2a:86:48:86:f7:0d:01:01:05:05:00:03:81:81:00:76:c2:9e:31:93:46:47:03:e7:da:6b:cb:6e:ea:a9:4b:4c:98:e7:78:91:59:13:2d:8f:cf:f4:3f:49:b5:79:2a:b9:f2:f7:ec:75:24:1d:a2:78:ec:af:07:75:01:c6:cd:55:4b:1f:6f:02:18:22:b6:13:4a:0c:ee:d2:69:d2:42:08:f3:e0:c1:a0:d0:b1:ba:cf:38:20:dc:14:77:01:cd:93:49:b4:23:ce:f3:a8:fb:cf:ea:2c:33:67:16:d8:71:53:30:d3:6d:13:3e:b3:db:9c:b7:be:c1:e8:b2:ab:56:c9:cb:33:02:96:8c:48:04:61:f9:a5:65:a7:13:0b:40:02:01:c3:30:82:01:bf:30:82:01:28:a0:03:02:01:02:02:08:0c:25:64:87:83:b0:53:b4:30:0d:06:09:2a:86:48:86:f7:0d:01:01:05:05:00:30:22:31:20:30:1e:06:03:55:04:03:13:17:77:77:77:2e:6b:7a:6e:79:74:72:7a:62:33:6e:6d:6e:32:63:68:2e:63:6f:6d:30:1e:17:0d:31:33:30:37:31:30:30:30:30:30:30:30:5a:17:0d:31:34:30:37:31:30:30:30:30:30:30:30:5a:30:22:31:20:30:1e:06:03:55:04:03:13:17:77:77:77:2e:6b:7a:6e:79:74:72:7a:62:33:6e:6d:6e:32:63:68:2e:63:6f:6d:30:81:9f:30:0d:06:09:2a:86:48:86:f7:0d:01:01:01:05:00:03:81:8d:00:30:81:89:02:81:81:00:c4:20:57:68:17:2d:b5:e0:7a:c5:a0:78:0b:23:f0:fd:54:be:6f:f3:89:ba:c5:5e:ac:03:ab:6e:e5:2c:a3:60:58:66:06:5f:66:b1:dc:bc:93:de:7c:c8:d5:8e:68:2e:ce:24:3c:a4:ec:30:ce:5f:b7:d6:a8:93:07:f8:d7:b9:4a:a0:24:65:65:cf:69:b5:f4:5b:83:10:f1:f7:47:3d:1a:d5:95:9a:4a:e6:0e:f0:8a:69:ee:7d:4c:ca:17:22:21:9f:66:2c:16:4f:a2:8a:ab:96:66:f7:f1:6e:d8:89:77:07:6b:c7:1a:42:89:60:a8:b1:9a:20:49:44:aa:7f:02:03:01:00:01:30:0d:06:09:2a:86:48:86:f7:0d:01:01:05:05:00:03:81:81:00:a1:7f:4a:f8:51:3e:fe:34:1b:10:4a:42:15:d9:8c:39:f7:4b:7c:97:27:f6:96:67:45:f6:f8:95:91:f5:53:72:0b:ee:47:1a:94:b3:48:be:ab:0a:be:5b:52:45:05:ea:35:6f:50:85:ea:fb:88:3c:ee:33:04:76:55:7a:9f:69:eb:5d:c5:20:a6:3c:04:e0:62:1a:8d:21:fd:16:0a:85:93:ef:7a:3e:23:e5:36:3c:27:82:e1:d0:02:f7:d1:2d:0c:6f:f9:f7:a1:48:06:92:75:78:3f:c1:64:05:15:9f:db:f4:a6:22:f0:d6:95:56:83:c7:bf:03:cd:9f:dd:9c:00:00:82:00:24:be:24:79:44:ec:06:96:f9:dd:a5:77:16:53:f9:eb:90:20:e8:a4:37:7e:0a:8d:5f:6d:6a:45:a4:33:bd:72:ac:00:01:00:01:00:00:08:53:85:8e:a1:04:04:94:c5:86:ea:02:04:04:56:3b:15:26:06:10:20:01:08:58:00:02:00:02:aa:bb:00:00:56:3b:15:26:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
我想弄清楚的是我在上面收到了多少数据包,以及它们包含什么信息,我认为应该收到 4 个数据包,但我不确定如果有人能提供帮助,那将是一个巨大的帮助,因为我真的确实需要尝试理解这一点。
编辑:
这是我当前的代码,但在理解接收到的数据时仍然存在问题 :(
import ssl
import socket
import struct
import binascii
s = socket.socket()
ssl_sock = ssl.wrap_socket(s)
ssl_sock.connect((" ", 443))
pkt = struct.pack(">HBHH", 0, 7, 2, 3)
ssl_sock.send(pkt)
peerAddr= [int(x) for x in ssl_sock.getpeername()[0].split(".")]
#recv_pkt = sock.recv(payload_len)
#print recv_pkt
#All recieved data printed
recv_pkt = ssl_sock.recv(1500)
#print recv_pkt
print ":".join("{:02x}".format(ord(c)) for c in recv_pkt)
print "Data recieved is above"
#while len(recv_pkt)<= 512
# payload = struct.unpack(">H")
# 512 - COMMAND_LEN - PAYLOAD_LEN = 512 - 1 - 509 = 2
CIRCID_LEN = 2
# default to v1
PAYLOAD_LEN = 509
#currently locking up at this section
circ_id, command = ssl_sock.recv(CIRCID_LEN), ssl_sock.recv(1)
print circ_id
print command
# according to spec, command is 7 if not using v1
# -> if not v1
if command != 7:
# Negotiate proto version and set PAYLOAD_LEN accordingly
PAYLOAD_LEN = 0
# finally, get the entire payload, and just that
payload = ssl_sock.recv(PAYLOAD_LEN)
print payload
#CellNetInfo
#cnetinf = recv_pkt(ssl_sock, 'CellNetInfo')
#ssl_sock.send(cnetinf.pack())
最佳答案
我还没有测试过这个,但它应该让你知道需要什么:
# Not sure if this is correct, I got it by:
# 512 - COMMAND_LEN - PAYLOAD_LEN = 512 - 1 - 509 = 2
CIRCID_LEN = 2
# default to v1
PAYLOAD_LEN = 509
circ_id, command = ssl_sock.recv(CIRCID_LEN), ssl_sock.recv(1)
# according to spec, command is 7 if not using v1
# -> if not v1
if command != 7:
# Here you need to "Negotiate proto version"
# Then, set PAYLOAD_LEN accordingly:
PAYLOAD_LEN = 0
# finally, get the entire payload, and just that
payload = ssl_sock.recv(PAYLOAD_LEN)
此外,由于套接字,使用 try/except block 可能会很好。
关于python - 理解/解码接收到的数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23905531/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!