Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. System.Net.Sockets for reading IP packets?

System.Net.Sockets for reading IP packets?

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpsysadminquestionworkspace
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tom Paluzzi
    wrote on last edited by
    #1

    I'm writing an application in C# that needs to sniff all IP packets coming into a certain server. I've tried to create a socket, bind, listening for connections, but I'm getting an exception when i try to listen on the created socket. It says "the operation is not supported on the type of object". I tried changing how I defined the IPEndPoint, and the SocketType and ProtocolType enumerations when creating the socket. Does anybody know the correct setup of the socket in order to inspect IP packets? Not at the TCP layer, but lower in OSI model. Is Here's the code. Thx, Tom try { // Build local end point IPAddress localAddr = IPAddress.Parse(Constants.LOCALHOST); IPEndPoint endpoint = new IPEndPoint(localAddr, Constants.PORT); // create new IP socket. server = new Socket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP); // SetupSocket(server); // Bind the socket to the local IP addr and port server.Bind(endpoint); // Start listening for connections, allowing for max # to be queued. server.Listen(Constants.MAX_CONNECTION_QUEUE); // loop until the service is stopped. while (ServiceStarted) { // Wait asynchronously for connections to be accepted. server.BeginAccept(new AsyncCallback(this.AcceptCallback), server); // yield if (ServiceStarted) { Thread.Sleep(new TimeSpan(0, 0, 5)); } . . . } } catch(SocketException e) { throw e; }

    S 1 Reply Last reply
    0
    • T Tom Paluzzi

      I'm writing an application in C# that needs to sniff all IP packets coming into a certain server. I've tried to create a socket, bind, listening for connections, but I'm getting an exception when i try to listen on the created socket. It says "the operation is not supported on the type of object". I tried changing how I defined the IPEndPoint, and the SocketType and ProtocolType enumerations when creating the socket. Does anybody know the correct setup of the socket in order to inspect IP packets? Not at the TCP layer, but lower in OSI model. Is Here's the code. Thx, Tom try { // Build local end point IPAddress localAddr = IPAddress.Parse(Constants.LOCALHOST); IPEndPoint endpoint = new IPEndPoint(localAddr, Constants.PORT); // create new IP socket. server = new Socket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP); // SetupSocket(server); // Bind the socket to the local IP addr and port server.Bind(endpoint); // Start listening for connections, allowing for max # to be queued. server.Listen(Constants.MAX_CONNECTION_QUEUE); // loop until the service is stopped. while (ServiceStarted) { // Wait asynchronously for connections to be accepted. server.BeginAccept(new AsyncCallback(this.AcceptCallback), server); // yield if (ServiceStarted) { Thread.Sleep(new TimeSpan(0, 0, 5)); } . . . } } catch(SocketException e) { throw e; }

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      AFAIK, what you are attempting to do can't be done using the .NET API as it provides only application level operations. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups