出力を読みやすく理解しやすくするために、Linux でnmap用の単純な ncurses GUI ラッパーを作成しています。ただし、出力の解析に関しては、POSIX 正規表現を使用してコード内のすべての式を評価するか、nmap 出力をgrep
、sed
またはなどのユーティリティにパイプする方が高速cut
ですか?
たとえば、サブネット内のオンライン ホストを取得したい場合、次のどのソリューションが適しているでしょうか?
pipe = popen("nmap -sn xxx.xxx.xxx.xxx/24", "r");
if (pipe == NULL) {
fprintf (stderr, "error creating the pipe: %s\n", strerror(errno));
exit (1);
}
while (!feof (pipe)) {
if (fgets (buff, BUFF_SIZE, pipe) != NULL) {
/* perform regex evaluations here */
printf ("%s", buff);
}
}
pclose (pipe);
対。
pipe = popen("nmap -sn xxx.xxx.xxx.xxx/24 | grep -E 'pattern' | ...", "r");
if (pipe == NULL) {
fprintf (stderr, "error creating the pipe: %s\n", strerror(errno));
exit (1);
}
while (!feof (pipe)) {
if (fgets (buff, BUFF_SIZE, pipe) != NULL) {
printf ("%s", buff);
}
}
pclose (pipe);