Click here to Skip to main content
15,883,940 members
Articles / Programming Languages / C#
Article

RawSocket Class-Create Network Monitoring (Packet Sniffing) Apps

Rate me:
Please Sign up or sign in to vote.
4.83/5 (17 votes)
11 Apr 2002 253K   3.2K   71   50
A class for creating Network Monitoring Programs

Introduction

This program illustrates the use of the RawSocket class which is written in C#. The class RawSocket is a packet sniffing class that fires notification events when an IP packet is received. This makes using the class simple. Just declare your RawSocket object, instantiate it, and register to be notified when the event fires.

When the event fires, you are sent event arguments which give your program access to everything in the IP packet including things like IP addresses, port numbers, protocols, message lengths, and of course the message contents.

The included Windows form is a simplified example which basically just shows the origination and destination IP addresses for all incoming packets on a listbox control. The Rawsocket class makes creating more sophisticated network monitoring applications easy.

This program relies on Winsock 2 and runs only on Win2000 or WinXP.

Please email comments and improvements to:

Kember Brown
kbrown@internetcds.com

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Lyle is a computer programmer in Vancouver, Washington.

Comments and Discussions

 
QuestionCAN SOMEONE HELP ME Pin
ayumiaw23-Jan-08 19:32
ayumiaw23-Jan-08 19:32 
GeneralARP are Packets not capturing Pin
Andy Rama2-Nov-06 2:00
Andy Rama2-Nov-06 2:00 
GeneralExcellent ! Pin
Gil.Y9-Jun-06 1:14
Gil.Y9-Jun-06 1:14 
QuestionProblems with Thread? Pin
Robse13-Apr-06 13:41
Robse13-Apr-06 13:41 
AnswerRe: Problems with Thread? Pin
Red_angelX24-Apr-07 20:55
Red_angelX24-Apr-07 20:55 
AnswerRe: Problems with Thread? Pin
sergios_rus10-Jul-07 13:59
sergios_rus10-Jul-07 13:59 
QuestionWSAIoctl vs. C# Pin
talbot31-Jan-06 5:09
talbot31-Jan-06 5:09 
GeneralSending packets received Pin
doctorcpu28-Sep-05 20:28
doctorcpu28-Sep-05 20:28 
GeneralExplain please Pin
Babs20041-Nov-04 13:34
sussBabs20041-Nov-04 13:34 
Generaldocumentation Pin
W M Suleiman23-Jun-04 5:48
W M Suleiman23-Jun-04 5:48 
QuestionThe owning process of a connection? Pin
Johan Danforth12-May-04 21:18
Johan Danforth12-May-04 21:18 
I'm sure many people have asked the same thing, but I need to get the name or id of the process that owns a certain ip port or connection on the machine. There are the undocumented API:s called AllocateAndGetTcpExTableFromStack and AllocateAndGetUdpExTableFromStack but as far as I know, they are only available for WinXP, and my program should run on win2k as well. Not sure if they are available on win2k3, but I guess they are.

So, any idea about how to solve this? Preferably in c# or vb.net.

/I need a signature I guess
GeneralDHCPDISCOVER Pin
Member 10577443-May-04 5:51
Member 10577443-May-04 5:51 
GeneralRe: DHCPDISCOVER Pin
BigRedAtwood13-Sep-04 10:41
BigRedAtwood13-Sep-04 10:41 
GeneralRe: DHCPDISCOVER Pin
Member 105774413-Sep-04 21:45
Member 105774413-Sep-04 21:45 
Questionhow about reading TCP header? Pin
mehro21-Feb-04 13:30
mehro21-Feb-04 13:30 
GeneralSpoofing Pin
Fad B5-Feb-04 0:45
Fad B5-Feb-04 0:45 
GeneralNot Run in Windows98 Pin
sbf200024-Aug-03 16:45
sbf200024-Aug-03 16:45 
GeneralRe: Not Run in Windows98 Pin
asdfuishdfusdhiufshdduisfdhdi28-May-04 6:15
asdfuishdfusdhiufshdduisfdhdi28-May-04 6:15 
GeneralDecoding Socket MessageBuffer Pin
Eric Gibson19-Jun-03 4:54
Eric Gibson19-Jun-03 4:54 
GeneralRe: Decoding Socket MessageBuffer Pin
kikon22-Jul-03 0:05
kikon22-Jul-03 0:05 
GeneralRe: Decoding Socket MessageBuffer Pin
Mike Hunt10-Mar-04 18:21
Mike Hunt10-Mar-04 18:21 
GeneralRe: Decoding Socket MessageBuffer Pin
Member 1560849-Jan-05 8:55
Member 1560849-Jan-05 8:55 
GeneralRe: Decoding Socket MessageBuffer Pin
dfhgesart26-Jan-05 9:28
dfhgesart26-Jan-05 9:28 
Questionwrong numberof packets? Pin
princedom27-May-03 7:24
princedom27-May-03 7:24 
QuestionRawSocket to NAT? Pin
dsandor6-May-03 12:36
dsandor6-May-03 12:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.