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
  1. Home
  2. General Programming
  3. C#
  4. question about port scanning

question about port scanning

Scheduled Pinned Locked Moved C#
question
3 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.
  • G Offline
    G Offline
    Green Fuze
    wrote on last edited by
    #1

    Hi everybody! I want to scan the ports on my computer, and I'm looking for the right class to do that. any clues please? thanks!

    M 1 Reply Last reply
    0
    • G Green Fuze

      Hi everybody! I want to scan the ports on my computer, and I'm looking for the right class to do that. any clues please? thanks!

      M Offline
      M Offline
      mikone
      wrote on last edited by
      #2

      Hi! I'm not sure about this but you could try to do it like this: System.Net.Sockets.TcpClient myclient = new System.Net.Sockets.TcpClient(); for (int i = 0; i < 65535; i++) { try { myclient.Connect("localhost", i); // Client was able to connect, hence the specified port 'i' is open... } catch { // An Exception was thrown, hence there was a problem while connecting.. port 'i' closed? } } This method is obviously not the best because it uses a try..catch statement and it will also throw an exception if a particular port is blocked by another application. To get around this issue you will have to extend the exceptionhandling massively. That's how i would do it but as already mentioned i'm pretty unexperienced... Good luck, mik

      G 1 Reply Last reply
      0
      • M mikone

        Hi! I'm not sure about this but you could try to do it like this: System.Net.Sockets.TcpClient myclient = new System.Net.Sockets.TcpClient(); for (int i = 0; i < 65535; i++) { try { myclient.Connect("localhost", i); // Client was able to connect, hence the specified port 'i' is open... } catch { // An Exception was thrown, hence there was a problem while connecting.. port 'i' closed? } } This method is obviously not the best because it uses a try..catch statement and it will also throw an exception if a particular port is blocked by another application. To get around this issue you will have to extend the exceptionhandling massively. That's how i would do it but as already mentioned i'm pretty unexperienced... Good luck, mik

        G Offline
        G Offline
        Green Fuze
        wrote on last edited by
        #3

        Hi I thought about this method, but its really not an efficient one. thanks alot anyway! :-)

        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