• C

Network Sniffer prog needed

Hi C gurus,

This Q is sort of a cross post as I asked it in the CGI area but didn't have much luck. (only unix heads about and while I am a fan of unix I need something that will compile under Micro$oft NT for my laptop).

Does anybody have a utility sitting in their toolbox which listens to a specified port (80 for my web work) and sends everything to the standard out?

Something nice and simple that I can have running in a DOS session would be perfect. No rocket science required. I need to debug some progs (CGI etc...) and do not have anything on hand that will give me this level of access to the network.

Source would be nice so I can fiddle with it (and maybe learn a thing or two about network programming..)

Who is Participating?

Improve company productivity with a Business Account.Sign Up

gadioConnect With a Mentor Commented:
 mravell, I think I have an answer for you. I had a problem like that and I solved it in the folowing manner. I set up a small program that does routing to and from the port that you want to snoop and another port (say 1234), and while routing the stream of data, prints them out. When you make your connection make it to the same host but indicate port 1234 (insted of www.xxx.yyy/zzz write www.xxx.yyy:1234/zzz), the routing is tranparent to the client and you get your info. I have such a program written in java. You can actually run it on any machine. If this solution is good for you I'll comment in the source.


mravellAuthor Commented:
Hi tflai,

I checked this stuff out but was really after something that isn't a commercial / pay through the nose type application.

My needs are very modest.

Monitor Port x (80) and dump everything to standard out.

I don't need a high-end monitoring package, just a scrap of C code that somebody may have lyig around.

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Socket Spy is a shareware.  And as far as I know, there are no full-fledge network snooper source code free anywhere.
It is not too difficult conceptually to implement a network snooper.  What you need is a promiscous protoocol driver and a application-layer shell that interact it through device I/O control and decode the packet headers for different protocols:  802.3, IP, TCP, ...  But to actually develop it is another thing...
But if you want a Winsock API snooper, I know where you can get a skeletal code for Winsock DLL replacement.
I'll second tflai's comments here but add a couple of points.  The only free network sniffers that I've seen are for MSDOS and unix/Linux systems.  In fact, there are several really good ones under Linux.  Under Windows, however, there is nothing in the low-price or free range.  
mravellAuthor Commented:
What I am after is more of a code snippet than a full package. I don't need any whistles or bells. Just something that listens to port 80 and dumps what it hears to the standard out.

No analysis, fancy graphics or logging features just a few lines of code that can eavesdrop on my own webserver.

mravellAuthor Commented:
Hi Gadio,

An interesteing idea. Not exactly what I had in mindbut it sounds as if it could do what I am after.

Please comment the code.

Here it is. For each connection that takes place you get a window opened and shows you the in and out going data. Note that when you monitor http protocol, the client will probably open connection for each image that is on the page. Pages with many images on them will couse a lot of windows to be opend.
Enjoy, G.

------------- snooper.java --------------

 * Program: snooper.java Written by gadio.
 * This program opens a window for each connection to a the port
 * that it bridges. The window have one area for the input and one
 * for the output. Once the communication in finished a close button
 * is enabled.

import java.awt.*;
import java.net.*;
import java.io.*;

public class snooper {

    public snooper (int origport, int newport ) {
        try {
            ServerSocket srvs = new ServerSocket( newport );
            while(1) {
                Socket inconnect = srvs.accept();
                Socket bridge = new Socket("",origport);
                snooperObj so = new snooperObj( inconnect, bridge );
        } catch( IOException e ) {

    public static void main(String args[]) {
        snooper snoopy = new snooper(80, 1234);

class snooperObj extends Frame {
    private Thread inMonitor, outMonitor;
    Socket inconnect;
    Socket bridge;
    TextArea in_txt, out_txt;
    connector con1, con2;
    Button close, clearin, clearout;

    public snooperObj( Socket incon, Socket brdg ) {
        inconnect = incon;
        bridge = brdg;
        setLayout( new BorderLayout());
        in_txt = new TextArea( 20, 20 );
        out_txt = new TextArea( 20, 20 );
        Panel north = new Panel();
        Panel center = new Panel();
        north.setLayout( new GridLayout(2,2));
        center.setLayout( new GridLayout(1,2));
        String time = (new java.util.Date(System.currentTimeMillis())).toString();
        north.add( new Label("into server ("+time+"):"));
        north.add( new Label("out from the server:"));
        north.add( clearin = new Button("Clear input"));
        north.add( clearout = new Button("Clear output"));
        add("North", north);
        add("Center", center);
        add("South", (close = new Button("Close window")));
        con1 = new connector( incon, bridge, in_txt, close );
        con2 = new connector( bridge, incon, out_txt, close );

    public boolean handleEvent( Event e ) {
        if( e.target == close ) {
            con1 = null;
            con2 = null;
            return true;
        if( e.target == clearin ) {
            return true;
        if( e.target == clearout ) {
            return true;
        return false;

class connector extends Thread {
    Socket from, to;
    TextArea txtout;
    Button end_button;

    public connector( Socket from_s, Socket to_s, TextArea txta, Button closeb ) {
        from = from_s;
        to = to_s;
        txtout = txta;
        end_button = closeb;

    public void run() {
        try {
            InputStream is = from.getInputStream();
            OutputStream os = to.getOutputStream();
            while(1) {
                int b = is.read();
                txtout.append( ""+(char)b );
        } catch(IOException e) {

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.