Skip to content

Instantly share code, notes, and snippets.

@polymorphm
Created February 1, 2014 21:03
Show Gist options
  • Save polymorphm/8758829 to your computer and use it in GitHub Desktop.
Save polymorphm/8758829 to your computer and use it in GitHub Desktop.
test of DPI (Deep Packet Inspection)
# -*- 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