Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- namespace SocketSniffConsole {
- class Program {
- public static void Main(string[] args) {
- byte[] buffer = new byte[4096];
- Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
- IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("192.168.0.3"), 0);
- socket.Bind(endpoint);
- socket.SetSocketOption(SocketOptionLevel.IP,
- SocketOptionName.HeaderIncluded,
- true);
- byte[] outValues = new byte[] { 1, 0, 0, 0 };
- byte[] inValues = new byte[] { 1, 0, 0, 0 };
- socket.IOControl(IOControlCode.ReceiveAll,
- inValues,
- outValues);
- while (true) {
- int read = socket.Receive(buffer);
- if (read >= buffer.Length) {
- Console.WriteLine("The packet was too big. I'm not going to handle it.");
- continue;
- }
- IPPacket p = IPPacket.Parse(buffer);
- Console.WriteLine("Version: " + p.Version);
- Console.WriteLine("Protocol: " + p.Protocol.ToString());
- Console.WriteLine("Length: " + p.TotalLength);
- Console.WriteLine("Source: " + p.Source.ToString());
- Console.WriteLine("Destination: " + p.Destination.ToString());
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement