0

Searched via google a lot about this question but I can't figure out a solution for this. I am trying to implement an MPI portscanner using the gnu c hping library. Only problem is, the hping homepage is down, and the usage is for shell only. I want to use hping to check if a port is open or closed (three-way-tcp handshake successful or not).

Are there any examples for this?

twasbrillig
  • 17,084
  • 9
  • 43
  • 67
lt_katana
  • 148
  • 3
  • 12

1 Answers1

0

You can execute hping and parse its output. Algorythm is simple:

  1. Use pipe() to create one-directional pipe
  2. Use fork() to create another process
  3. In child process:
  4. Use dup2() to substitute stdout by output end of pipe. Don't forget to close input end of pipe.
  5. Use execlp() to execute hping
  6. In parent process:
  7. hping output would be available in input end of pipe. Don't forget to close output end of pipe.
Max
  • 36
  • 3
  • Do i really need a pipe to get the return value of hping accessable in the main prog? Basically i have no idea of piping (except usage of pipes in bash). Another problem is that i have no idea what the return value basically is. – lt_katana Nov 14 '14 at 11:31
  • You can call hping via system("hping > results.txt") and parse results.txt file. – Max Nov 14 '14 at 15:47
  • Have one more question but i don't want to open up another silly question. I piped the output of hping3 to my parent process but when i read the pipe theres no output. – lt_katana Nov 27 '14 at 13:25
  • Seems like there are some issues with hping3 and the output redirection according to posts i found on the net. ( hping3 10.1.1.1 -c 1 -q ) >/filepath/filename should work, but is not tested yet – lt_katana Nov 28 '14 at 11:08
  • I don't know how hping3 works, but I assume he may print it's data via stderr. – Max Dec 01 '14 at 11:24