当前位置: 首页>>代码示例>>C++>>正文


C++ Scanner::initPktSniffing方法代码示例

本文整理汇总了C++中Scanner::initPktSniffing方法的典型用法代码示例。如果您正苦于以下问题:C++ Scanner::initPktSniffing方法的具体用法?C++ Scanner::initPktSniffing怎么用?C++ Scanner::initPktSniffing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scanner的用法示例。


在下文中一共展示了Scanner::initPktSniffing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]) {

	ArgsParser ps_args;	// object to parse program arguments
	// ps_args.fill_resv_IPs();	// keep an account of all reserved IPs that are not allowed to be scanned
	ps_args.parse_args(argc, argv);

	// print IPs
	cout << "\n"<< "=============== IPs to be scanned ===============" << endl << endl;
	ps_args.print_setelems(ips_set);

	// print ports
	cout << endl << "=============== Ports to scan ===============" << endl << endl;
	ps_args.print_setelems(ports_set);

	// print number of threads to run
	cout << endl << "=============== Threads ===============" << endl << endl;
	cout << "Number of threads specified: " << ps_args.get_threads() << endl << endl;

	// print type/s of scans specified
	cout << endl << "=============== Scan types ===============" << endl << endl;
	ps_args.print_setelems(scans_set);
	cout << endl;

	// create a work queue
	Jobber jobman;
	jobman.createJobs();

	/** register an alarm signal (SIGALRM) handler **/
	struct sigaction act;
	act.sa_handler = checkPulse;	// handler function
	sigemptyset(&act.sa_mask);	// no signals to be masked; to receive all signals
	act.sa_flags = 0;
	sigaction(SIGALRM, &act, 0);	// register signal to type SIGALRM to be handled

	/** display scan start time **/
	time_t init_time, fin_time;	// for storing time values at beginning of program execution
	struct tm *abouttime;	// store current time details in this structure
	char buffer[100];	// string to display to stdout
	time(&init_time);	// get current time
	abouttime = localtime(&init_time);
	strftime(buffer, sizeof buffer, "\nportScanner started at %F %T %Z.", abouttime);
	cout << buffer << endl;

	cout << "Scanning.." << std::flush;
	alarm(1);	// generate alarm signal to check scan progress

	// let the scanning begin
	Scanner scanman;
	if (ps_args.get_threads() == 0) {	// no threads
		scanman.initPktSniffing();
		scanman.runJobs();
		scanman.printScanResults();
	} else {	// multi-threaded
		cout << "\nthreads" << endl;
	}

	alarm(0);	// turn alarm off
	
	/* display end time */
	time(&fin_time);	// get time at end
	abouttime = localtime(&fin_time);
	memset(buffer, 0x0, sizeof buffer);	// flush out char buffer
	strftime(buffer, sizeof buffer, "\nportScanner ended at %F %T %Z.", abouttime);
	fprintf( stdout, "%s Scan took %.3f seconds.\n\n", buffer, difftime(fin_time, init_time) );	// output difference in start and end time too

	return 0;
}
开发者ID:abdulmudabir,项目名称:portScanner,代码行数:67,代码来源:portScanner.cpp


注:本文中的Scanner::initPktSniffing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。