Results 1 to 1 of 1
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,222
    Thanks Thanks Given 
    211
    Thanks Thanks Received 
    2,230
    Thanked in
    292 Posts
    Rep Power
    10

    Simple Packet Sniffer Source

    This is old, but maybe useful example of packet sniffer application written on C#

    Author defines a structure using struct to store IP header in it.

    Code:
    [StructLayout(LayoutKind.Explicit)] 
    public struct IpHeader
    {
    [FieldOffset(0)] public byte ip_verlen; // IP version and IP Header length
    [FieldOffset(1)] public byte ip_tos; // Type of service
    [FieldOffset(2)] public ushort ip_totallength; // total length of the packet
    [FieldOffset(4)] public ushort ip_id; // unique identifier
    [FieldOffset(6)] public ushort ip_offset; // flags and offset
    [FieldOffset(8)] public byte ip_ttl; // Time To Live
    [FieldOffset(9)] public byte ip_protocol; // protocol (TCP, UDP etc)
    [FieldOffset(10)] public ushort ip_checksum; //IP Header checksum
    [FieldOffset(12)] public long ip_srcaddr; //Source address
    [FieldOffset(16)] public long ip_destaddr;//Destination Address
    }
    StructLayoutAttribute attribute has been used to arrange the members of this structure in the necessary positions.

    After that a socket using the Socket class has been created:

    Code:
    socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
    It should be Raw socket and bind socket to defined IP And called function IOControl(it must be called after you call Bind) IOControl it's analogue of WSAIoctl API function.

    Author put first parameter of IOControl to SIO_RCVALL(0x98000001). After packets have been received, they should be analyzed.

    Author calculates length of the data in packets as follows: "protocol header length (TCP, UDP, ICMP etc)" + "data" without length "ip header length". Total length is "ip header length" + "protocol header length(TCP, UDP, ICMP etc)" + "data"

    Please register or login to download attachments.

    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

  2. The Following User Says Thank You to Dwar For This Useful Post:


Similar Threads

  1. [Tool] Perfect World Packet Sniffer Cheat Engine plugin
    By Grooguz in forum Perfect World Bots, Cheats
    Replies: 10
    Last Post: 2017-07-08, 11:17 AM
  2. [C++] How to make a simple bot
    By Dwar in forum Programming Tutorials
    Replies: 3
    Last Post: 2014-10-04, 12:53 PM
  3. [C#] WinPCap Packet Sniffer Source
    By Dwar in forum VB, .NET Framework
    Replies: 2
    Last Post: 2014-08-24, 07:47 PM
  4. [Release] Simple ASM Injector
    By pohkak in forum Files & Tools
    Replies: 1
    Last Post: 2012-01-07, 05:22 PM
  5. [C++] Simple Proxy Reference
    By Dwar in forum Programming Tutorials
    Replies: 1
    Last Post: 2011-11-18, 10:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •