0

出力を読みやすく理解しやすくするために、Linux でnmap用の単純な ncurses GUI ラッパーを作成しています。ただし、出力の解析に関しては、POSIX 正規表現を使用してコード内のすべての式を評価するか、nmap 出力をgrepsedまたはなどのユーティリティにパイプする方が高速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);
4

1 に答える 1

0

ベンチマークを行います。テストにはhttp://goo.gl/E3jbMを使用することをお勧めします。ベンチマークに関するヘルプが必要な場合はお知らせください。

于 2012-02-13T01:08:52.900 に答える