Skip to content

Instantly share code, notes, and snippets.

@KhorAMus
Last active March 26, 2016 11:17
Show Gist options
  • Save KhorAMus/b1dddc9a7b64faad44e2 to your computer and use it in GitHub Desktop.
Save KhorAMus/b1dddc9a7b64faad44e2 to your computer and use it in GitHub Desktop.
exercise 2.5
Программа для отправки:
import requests
payload = {
"github": "MyNickName",
"Name": "MyName",
"Surname": "MySurname"
}
resp = requests.post('http://httpbin.org/post',
headers={
'Host': 'httpbin.org',
'Accept': '*/*',
'Content-Type': 'application/x-www-form-urlencoded'
},
data = payload
)
# also output headers in response
answer_string = str(resp.headers).replace(', ', '\n')[1:-1] + "\n"
answer_string += resp.content.decode(resp.apparent_encoding)
print(answer_string)
Трафик, перехваченный программой tcpdump
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
15:59:55.286314 IP (tos 0x0, ttl 64, id 31424, offset 0, flags [DF], proto TCP (6), length 60)
10.0.2.15.47176 > 54.175.219.8.80: Flags [S], cksum 0x1df5 (incorrect -> 0xcec8), seq 3046766837, win 29200, options [mss 1460,sackOK,TS val 229941 ecr 0,nop,wscale 7], length 0
15:59:55.451251 IP (tos 0x0, ttl 64, id 1007, offset 0, flags [none], proto TCP (6), length 44)
54.175.219.8.80 > 10.0.2.15.47176: Flags [S.], cksum 0xb6e1 (correct), seq 4480001, ack 3046766838, win 65535, options [mss 1460], length 0
15:59:55.451293 IP (tos 0x0, ttl 64, id 31425, offset 0, flags [DF], proto TCP (6), length 40)
10.0.2.15.47176 > 54.175.219.8.80: Flags [.], cksum 0x1de1 (incorrect -> 0x5c8e), ack 1, win 29200, length 0
15:59:55.451634 IP (tos 0x0, ttl 64, id 31426, offset 0, flags [DF], proto TCP (6), length 302)
10.0.2.15.47176 > 54.175.219.8.80: Flags [P.], cksum 0x1ee7 (incorrect -> 0x32fd), seq 1:263, ack 1, win 29200, length 262: HTTP, length: 262
POST /post HTTP/1.1
Content-Length: 47
Accept-Encoding: gzip, deflate
Connection: keep-alive
Accept: */*
User-Agent: python-requests/2.9.1
Host: httpbin.org
Content-Type: application/x-www-form-urlencoded
github=MyNickName&Surname=MySurname&Name=MyName[!http]
15:59:55.451950 IP (tos 0x0, ttl 64, id 1008, offset 0, flags [none], proto TCP (6), length 40)
54.175.219.8.80 > 10.0.2.15.47176: Flags [.], cksum 0xcd98 (correct), ack 263, win 65535, length 0
15:59:55.622143 IP (tos 0x0, ttl 64, id 1009, offset 0, flags [none], proto TCP (6), length 730)
54.175.219.8.80 > 10.0.2.15.47176: Flags [P.], cksum 0xa4aa (correct), seq 1:691, ack 263, win 65535, length 690: HTTP, length: 690
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 26 Mar 2016 10:59:55 GMT
Content-Type: application/json
Content-Length: 470
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
{
"args": {},
"data": "",
"files": {},
"form": {
"Name": "MyName",
"Surname": "MySurname",
"github": "MyNickName"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "47",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.9.1"
},
"json": null,
"origin": "212.193.94.11",
"url": "http://httpbin.org/post"
}
15:59:55.622252 IP (tos 0x0, ttl 64, id 31427, offset 0, flags [DF], proto TCP (6), length 40)
10.0.2.15.47176 > 54.175.219.8.80: Flags [.], cksum 0x1de1 (incorrect -> 0x544e), ack 691, win 30360, length 0
15:59:55.623138 IP (tos 0x0, ttl 64, id 31428, offset 0, flags [DF], proto TCP (6), length 40)
10.0.2.15.47176 > 54.175.219.8.80: Flags [F.], cksum 0x1de1 (incorrect -> 0x544d), seq 263, ack 691, win 30360, length 0
15:59:55.623512 IP (tos 0x0, ttl 64, id 1010, offset 0, flags [none], proto TCP (6), length 40)
54.175.219.8.80 > 10.0.2.15.47176: Flags [.], cksum 0xcae5 (correct), ack 264, win 65535, length 0
15:59:55.783607 IP (tos 0x0, ttl 64, id 1011, offset 0, flags [none], proto TCP (6), length 40)
54.175.219.8.80 > 10.0.2.15.47176: Flags [F.], cksum 0xcae4 (correct), seq 691, ack 264, win 65535, length 0
15:59:55.783638 IP (tos 0x0, ttl 64, id 3730, offset 0, flags [DF], proto TCP (6), length 40)
10.0.2.15.47176 > 54.175.219.8.80: Flags [.], cksum 0x544c (correct), ack 692, win 30360, length 0
В трафике видим множественные обмены пакетами, так как передача происходит по протоколу tcp. Можем также видеть полученный от httpbin ответ
в удобочитаемом виде.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment