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 / C++ / MFC
  4. TCP port detection/scanning

TCP port detection/scanning

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
9 Posts 4 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.
  • J Offline
    J Offline
    Jorgen Sigvardsson
    wrote on last edited by
    #1

    Does anybody know of a good technique to detect if a TCP-port is open on a server, without fully connecting to it? I need to do a half-way TCP-connect, so that the server's accept() isn't executed. The server becomes quite "upset" if I just connect and disconnect, not adhering to its protocol. The protocol is proprietary, and I do not have the source code for the server, so I can't add my own tweaks to it. Hence I need to "fool" it on TCP-level. I know there are implementations such as NMap out there, but I figured I'd ask here for the basic techniques first, before taking a plunge into complex multiplatform sources. Note: I'm no dummy, so you don't have to give me tons of source code. Some hints would do just fine. ps. I wouldn't be offended, should you give me code :-D -- An eye for an eye will only make the world blind.

    A D 3 Replies Last reply
    0
    • J Jorgen Sigvardsson

      Does anybody know of a good technique to detect if a TCP-port is open on a server, without fully connecting to it? I need to do a half-way TCP-connect, so that the server's accept() isn't executed. The server becomes quite "upset" if I just connect and disconnect, not adhering to its protocol. The protocol is proprietary, and I do not have the source code for the server, so I can't add my own tweaks to it. Hence I need to "fool" it on TCP-level. I know there are implementations such as NMap out there, but I figured I'd ask here for the basic techniques first, before taking a plunge into complex multiplatform sources. Note: I'm no dummy, so you don't have to give me tons of source code. Some hints would do just fine. ps. I wouldn't be offended, should you give me code :-D -- An eye for an eye will only make the world blind.

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      I took print out of your query and went to desks of TCP experts , The answers 1) Call lsof on unix flavoured OSs 2) net stat -p tcp (u can use the rexec(IP , Cmd ) to execute this command at the remote server , but i am not sure of rights issues of RPC ) 3) Ethreal tool can help (but u r searching for code ..almost useless) P.S : not sure of the rexec() function name . Which OS u r talkign abt ?

      J 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        Does anybody know of a good technique to detect if a TCP-port is open on a server, without fully connecting to it? I need to do a half-way TCP-connect, so that the server's accept() isn't executed. The server becomes quite "upset" if I just connect and disconnect, not adhering to its protocol. The protocol is proprietary, and I do not have the source code for the server, so I can't add my own tweaks to it. Hence I need to "fool" it on TCP-level. I know there are implementations such as NMap out there, but I figured I'd ask here for the basic techniques first, before taking a plunge into complex multiplatform sources. Note: I'm no dummy, so you don't have to give me tons of source code. Some hints would do just fine. ps. I wouldn't be offended, should you give me code :-D -- An eye for an eye will only make the world blind.

        D Offline
        D Offline
        dharani
        wrote on last edited by
        #3

        In fact I replied to your message (but shows "Ananymous" as I di dnot log in while replying) redindian

        1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          Does anybody know of a good technique to detect if a TCP-port is open on a server, without fully connecting to it? I need to do a half-way TCP-connect, so that the server's accept() isn't executed. The server becomes quite "upset" if I just connect and disconnect, not adhering to its protocol. The protocol is proprietary, and I do not have the source code for the server, so I can't add my own tweaks to it. Hence I need to "fool" it on TCP-level. I know there are implementations such as NMap out there, but I figured I'd ask here for the basic techniques first, before taking a plunge into complex multiplatform sources. Note: I'm no dummy, so you don't have to give me tons of source code. Some hints would do just fine. ps. I wouldn't be offended, should you give me code :-D -- An eye for an eye will only make the world blind.

          D Offline
          D Offline
          dharani
          wrote on last edited by
          #4

          As you know the server IP + port ,you can filter the netstat -p command's results and find if the port is established or not . Right ? redindian

          J 1 Reply Last reply
          0
          • A Anonymous

            I took print out of your query and went to desks of TCP experts , The answers 1) Call lsof on unix flavoured OSs 2) net stat -p tcp (u can use the rexec(IP , Cmd ) to execute this command at the remote server , but i am not sure of rights issues of RPC ) 3) Ethreal tool can help (but u r searching for code ..almost useless) P.S : not sure of the rexec() function name . Which OS u r talkign abt ?

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #5

            I thought it was obvious that I'm talking about Windows, especially considering the fact that this message board is called "Visual C++". :) Anyway, I need to do it programatically, so I can't just launch a second process, or make it a manual operation for the end user to do.

            1 Reply Last reply
            0
            • D dharani

              As you know the server IP + port ,you can filter the netstat -p command's results and find if the port is established or not . Right ? redindian

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #6

              I don't want to establish a connection - it confuses the server, because I don't follow the protocol. I just want to detect the presence of an open port on a particular IP address. I've found the TCP state charts, and it seems that all I need to do is to send a TCP/SYN-message, and wait for a TCP/SYN_ACK message. Then I know there is a process listening on that port. Then my plan is to send a TCP/RST to reset that connection sequence, thus preventing the server from acquiring a socket.

              H 1 Reply Last reply
              0
              • J Jorgen Sigvardsson

                I don't want to establish a connection - it confuses the server, because I don't follow the protocol. I just want to detect the presence of an open port on a particular IP address. I've found the TCP state charts, and it seems that all I need to do is to send a TCP/SYN-message, and wait for a TCP/SYN_ACK message. Then I know there is a process listening on that port. Then my plan is to send a TCP/RST to reset that connection sequence, thus preventing the server from acquiring a socket.

                H Offline
                H Offline
                HumanOsc
                wrote on last edited by
                #7

                Hello... Look at: http://www.codeproject.com/internet/NagTPortScanner.asp[^] Not very good explained but a smart introducion about TCP SYN scanning... # Best regards... :)

                J 1 Reply Last reply
                0
                • H HumanOsc

                  Hello... Look at: http://www.codeproject.com/internet/NagTPortScanner.asp[^] Not very good explained but a smart introducion about TCP SYN scanning... # Best regards... :)

                  J Offline
                  J Offline
                  Jorgen Sigvardsson
                  wrote on last edited by
                  #8

                  Thank you for that link! Unfortunately it makes use of win/libpcap, which has a rather fascist license requirement, which states I must reproduce the copyright information. :grumble: It's on my list though, in case I don't find something else. So, once again, thank you!

                  H 1 Reply Last reply
                  0
                  • J Jorgen Sigvardsson

                    Thank you for that link! Unfortunately it makes use of win/libpcap, which has a rather fascist license requirement, which states I must reproduce the copyright information. :grumble: It's on my list though, in case I don't find something else. So, once again, thank you!

                    H Offline
                    H Offline
                    HumanOsc
                    wrote on last edited by
                    #9

                    Hello again... Look at: http://www.c-schell.de/home/cpp/source/gull.c[^] This an example in pure c... I believe this can be helpful for your problem, too...

                    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