我正在为Linux下的nmap编写一个简单的ncurses包装器,以便更容易地阅读和理解输出。但是,在解析输出时,使用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);发布于 2012-02-13 01:08:52
做你的基准。我建议使用http://goo.gl/E3jbM进行测试。如果你在基准测试方面需要帮助,请告诉我。
https://stackoverflow.com/questions/9252213
复制相似问题