Ethereal-users: Re: [Ethereal-users] How can I analyse browser http header?

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Gerald Combs <gerald@xxxxxxxxxxxx>
Date: Thu, 22 Dec 2005 08:33:34 -0600
>From there you can save the TCP stream to a file, and replay it to your
heart's content.

Attached is a Python script I wrote a while back that uses this feature
to replay an HTTP request in order to download the price list from a
large networking vendor who shall remain nameless.  I'm not sure how
easily it translates to C, but it should get you started.

Jule Slootbeek wrote:
> If you grab a trace of the entire transaction, right click on one of the
> HTTP packets and click on "Follow TCP Stream". This will give you all
> the text passed to and from the web server.
> Regards,
> Jule 
> 
> -----Original Message-----
> From: ethereal-users-bounces@xxxxxxxxxxxx
> [mailto:ethereal-users-bounces@xxxxxxxxxxxx] On Behalf Of Mike Zang
> Sent: Wednesday, December 21, 2005 11:54 PM
> To: ethereal-users@xxxxxxxxxxxx
> Subject: [Ethereal-users] How can I analyse browser http header?
> 
> I have a account in domains.yahoo.com, I can login and modify my
> information by browser.
> 
> Now I want to make c program on FC4 to do the same thing, so I tried to
> analyse http header when I use browser to maintenance my account.
> 
> How can I analyse the http header? is this program can do the same thing
> as browser?
> 
> 
> 
> _______________________________________________
> Ethereal-users mailing list
> Ethereal-users@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-users
> 
> _______________________________________________
> Ethereal-users mailing list
> Ethereal-users@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-users

#/usr/bin/env python
#
# Price List - Grabs the latest price list from a large networking vendor
# who shall remain nameless.
#
# Copyright 2002 Gerald Combs <gerald@xxxxxxxxxxxx>
#
# A file named 'price list request.txt' is required for proper operation.  To
# create this file, do the following:
#
# - Go to LargeNetworkingVendor's site and find the price list download page.
#   Do NOT download the price list yet, however.
# - Fire up your favorite network protocol analyzer that supports TCP stream 
#   viewing.
# - Start a capture on port 80.
# - Download the price list.
# - Stop the capture, view the stream containing the price list download, and
#   save the contents to 'price list request.txt'.


import httplib
import calendar
from time import strftime, localtime
import sys

req_file = 'price list request.txt'
price_list = strftime(
        r'/path/to/saved price list %Y-%m-%d.xls',
        localtime() )

fd = open(req_file, 'r')

sess = httplib.HTTPConnection('www.largenetworkingvendor.com')

# Grab and send the first line (the request)
line = fd.readline()
line = line.strip()

req_type, req_path, req_extra = line.split(None, 2)

print 'Sending request...',
sess.putrequest(req_type, req_path)

# Grab and send the headers
in_headers = 1
while in_headers:
        line = fd.readline()
        line = line.strip();
        if (line == ''):
                in_headers = 0
                break

        header, data = line.split(None, 1)
        header = header[0:len(header) - 1]
        sess.putheader(header, data)

sess.endheaders()

# Grab and send the POST data
if (req_type == "POST"):
        line = fd.readline()
        line = line.strip()
        sess.send(line)

fd.close()

# Read the response
resp = sess.getresponse()
if resp.status != 200:
        print 'Error %d: %s' % (resp.status, resp.reason)
else:
        print 'Success!\nReading file...',
        try:
                data = resp.read()
        except:
                dlen = len(data) / 1024
                if dlen < 1000:
                        print 'error: only %d KB read' % (dlen)
                        sys.exit(1)
        fd = open(price_list, 'wb')
        fd.write(data)
        fd.close()
        print 'done.'