4

I want to invoke nmap functionalities like OS detection in C++.

In python, import nmap allows to use nmap functions. Similarly, is there any way I can do it in C++?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
arnav
  • 61
  • 1
  • 2

2 Answers2

4

You can run the nmap as an external program and read its output through a pipe using popen().

Example

FILE *pin = popen("nmap -p 123 10.0.1.0/24","r");
if ( pin ) {
   while (!feof(pin)) {
      const char *line = readLine(pin);
      printf("%s\n", line);
   }
   pclose(pin);
} 
0

The Python nmap package simply launches the Nmap command and parses the XML output. This is certainly something you could do in C++, though you'd have to work out the parsing yourself. I'm not aware of an existing Nmap-output-parsing library in C or C++ like there are for Python, Perl, Ruby, etc.

bonsaiviking
  • 5,825
  • 1
  • 20
  • 35