Created
February 1, 2014 21:03
-
-
Save polymorphm/8758829 to your computer and use it in GitHub Desktop.
test of DPI (Deep Packet Inspection)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: python; coding: utf-8 -*- | |
assert str is not bytes | |
# DPI -- Deep Packet Inspection | |
def test_dpi(host, data): | |
import socket | |
ss = socket.create_connection((host, 80), timeout=10.0) | |
s = ss.makefile(mode='rwb') | |
print('*** family:{} type:{} proto:{} ***'.format(ss.family, ss.type, ss.proto)) | |
s.write(data) | |
s.flush() | |
res_buf = b'' | |
while True: | |
try: | |
buf = s.read(1) | |
except socket.timeout: | |
break | |
if not buf: | |
break | |
res_buf += buf | |
return res_buf | |
print(test_dpi( | |
'penza.domru.ru', | |
b'GET /posts/729413 HTTP/1.1\r\nUser-Agent: xxx123\r\nHost: danbooru.donmai.us\r\n\r\n' | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment