Simple HTTP header Sniffer Using python socket module

hello Friends,


                                  Today, In This Tutorial, I'm Gonna to Show You How We Can Capture HTTP Header Packet Using Python and Socket Module.


                                              This Script is Very Useful For Examine Any Websites Cookie Technique, Banner Grabbing, Information Gathering And Also Very Helpful To Create Website Scraping Script.

Ok So, Let's Start Here,

In this Script,

first of all we will Capture all packets using socket and after caputring packet.
we can extract packets for filtering our useful data.


Here, I am explaining my script step by step

1. line is for importing socket module

3. line is creating socket handler for packet sniffing

5. loop

6. reading captured packets

8. verify that extracted packet is HTTP Header

I know This script look very easy. and its looking easy because here we are writing codes in python.


HTTP Header Sniffing Python Codes


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import socket

s=socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0800))

while True:
 data=s.recvfrom(65565)
 try:
  if "HTTP" in data[0][54:]:
    print "[","="*30,']'
    raw=data[0][54:]
    if "\r\n\r\n" in raw:
     line=raw.split('\r\n\r\n')[0]
     print "[*] Header Captured "
     print line[line.find('HTTP'):]
    else:
     print raw
  else:
   #print '[{}]'.format(data)
   pass
 except:
  pass

TCP Header




forr Downloading This Script Click Here

Done!







Thanks For Support
Please, Feel Free To Leave A Comment If Our Article has Helped You.
Written By:
S.S.B
surajsinghbisht054@gmail.com


Share this

Related Posts

Previous
Next Post »