tags:

views:

1140

answers:

6

Is there a way to monitor and capture all outgoing HTTP requests from a machine using C#?

I need a browser independent way of logging visited URLs.

+9  A: 

I use fiddler ( http://www.fiddler2.com )

Rob
+2  A: 

You're probably going to save lots of time and effort with some kind of proxy setup. A decent local-machine solution would be Fiddler (requires Windows), or something like a Squid server for a networked solution.

ZombieSheep
+3  A: 

You may want to use existing network interfaces capturing libraries like pcap or winpcap to do so. Rewriting all the necessary stuff by yourself would be quite time expensive.

Link to Pcap

Link to WinPcap

Edit : Just saw someone also wrote the C# bindings to winpcap : SharpPcap

WiseTechi
The other posts were helpful, but the only way I could get the app to capture outgoing (as well as incoming) packets was to install the WinPcap driver and call it using the SharpPcap library. Turns out some OS/hardware setups don't let you get at the outgoing packets using plain old C# sockets.
Robert Morgan
+3  A: 

Sounds like you're after some kind of "packet sniffing" utility.

Here's a couple of links to articles on the Code Project site for packet sniffers (with downloadable source code) written in C#:

Packet Capture and Analayzer

A Network Sniffer in C#

If you're just after capturing visited URL's, these utilities may be overkill, however, you'll be able to extract a URL from your HTTP packets and discard the rest, however, you may also wish to capture all packet information, in which case, these utilities will help.

CraigTP
I'm looking for a http sniffer code in C.. Can you please suggest any resources..
trinity
A: 

Also, writing a simple http proxy for this purpose in C# is a trivial task.

Vasil
Do you have any links to resources about this?
CalvinR
you'll need something like these to get started:http://www.jmarshall.com/easy/http/http://www.codeproject.com/KB/IP/dotnettcp.aspx
Vasil
+1  A: 

I hope if Wirehark works for you. It's free and cross-platform. Also, "Wireshark is the world's foremost network protocol analyzer, and is the de facto (and often de jure) standard across many industries and educational institutions"

Have look, Wireshark-Wikipedia

Ahmed
Thanks for the suggestion but I can't see a way of calling this from C#. Besides, it's built on WinPcap so I might as well just use that.
Robert Morgan
Ummm, I hope, you can use WinPcap as you said in your comment for correct answer.
Ahmed