亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? kddcup.c

?? 這是一個用遺傳算法對KDDCUP數據集
?? C
?? 第 1 頁 / 共 2 頁
字號:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

#define POPSIZE 5000
#define GEN   100   
#define ATTRIB 8   //	8個基本屬性

//全局變量
int gen=0; 
double pc=0.90;
double pm=0.10;
int normalcount; //正常模式的總數量
int attackcount; //攻擊模式的總數量
int bestindex;
int worstindex;


struct kddcup_data { /* KDDCUP數據結構*/
	 int duration; 
    char protocol_type[10];
	char service[10];
	char flag[10];
	 int src_bytes;
	 int dst_bytes;
	 int land;
     int wrong_fragment;
	 int urgent;
	 int hot;
	 int num_failed_logins;
	 int logged_in;
	 int num_compromised;
	 int root_shell;
	 int su_attempted;
	 int num_root;
	 int num_file_creations;
	 int num_shells;
	 int num_access_files;
	 int num_outbound_cmds;
	 int is_host_login;
	 int is_guest_login;
	 int count;
	 int srv_count;
   float serror_rate;
   float srv_serror_rate;
   float rerror_rate;
   float srv_rerror_rate;
   float same_srv_rate;
   float diff_srv_rate;
   float srv_diff_host_rate;
     int dst_host_count;
     int dst_host_srv_count;
   float dst_host_same_srv_rate;
   float dst_host_diff_srv_rate;
   float dst_host_same_src_port_rate;
   float dst_host_srv_diff_host_rate;
   float dst_host_serror_rate;
   float dst_host_srv_serror_rate;
   float dst_host_rerror_rate;
   float dst_host_srv_rerror_rate;
    char idstype[10];
};



struct individual // 定義染色體數據結構  選擇關于TCP連接的基本屬性部分
{
	 int duration; 
     int protocol_type;
	 int service;
	 int flag;
	 int src_bytes;
	 int dst_bytes;
	 int land;
     int wrong_fragment;

	double fitness;
};

// sleep(5000);

struct kddcup_data kdata[5000]; 
struct kddcup_data ddata[5000]; 

struct individual bestindividual;
struct individual worstindividual;
struct individual thebest;
struct individual population[POPSIZE];

void readfiles();
int stringcmp(char *s1, char *s2);
void initpopulation();
void countfitness();
void select();
void cross();
void mutation();
void fbwest();

void main() 
{ 

    //printf("%d,%s,%s,%s,%s,%f",kdata[1].duration,kdata[1].protocol_type,kdata[1].service,kdata[1].flag,kdata[1].idstype,kdata[1].dst_host_srv_rerror_rate);  

	readfiles();

	initpopulation();//初始化種群

	countfitness();

	fbwest();

	gen=0;

	while( gen<GEN )
	{
		select();
		cross();
		mutation();
		countfitness();
		fbwest();	//如果父代的最優適應度值比子代最優適應度值大,則復制代替子代最差適應度值
		gen++;
		printf("\n the best fitness is : %f .\n",thebest.fitness);
	}
	printf("\n the the the  best best best fitness is : %f .\n",thebest.fitness);
	printf("\n%d,%d,%d,%d,%d,%d,%d,%d\n",thebest.duration,thebest.protocol_type,thebest.service,thebest.flag,thebest.src_bytes,thebest.dst_bytes,thebest.land,thebest.wrong_fragment);

}



void readfiles()
{
	FILE *fp; 
	char ch;
	int i,j;

	if((fp=fopen("normal.txt","r"))==NULL) 
		printf("can not open file\n"); 
	i=0;
	while(!feof(fp)) //文件輸入到KDDCUP數據結構中
	{
		fscanf(fp,"%d",&kdata[i].duration);

		fscanf(fp,"%c",&ch); //得到TXT文件中的,號

		fscanf(fp,"%c",&ch); //得到TXT文件中的,和,間的字符串
		j=0;
	while (ch!=','&&ch!='\n') 
	{
		kdata[i].protocol_type[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);
	}
		kdata[i].protocol_type[j]='\0'; //寫入字符串結束標志


	fscanf(fp,"%c",&ch); //作用同上
	j=0;
	while (ch!=',') 
	{
		kdata[i].service[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);
	//	printf("%c\n",ch);
	}
	kdata[i].service[j]='\0';

	fscanf(fp,"%c",&ch); //作用同上
	j=0;
	while (ch!=',') 
	{
		kdata[i].flag[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);

	}
	kdata[i].flag[j]='\0';


		fscanf(fp,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,",&kdata[i].src_bytes,&kdata[i].dst_bytes,&kdata[i].land,&kdata[i].wrong_fragment,&kdata[i].urgent,&kdata[i].hot,&kdata[i].num_failed_logins,&kdata[i].logged_in,&kdata[i].num_compromised,&kdata[i].root_shell,&kdata[i].su_attempted,&kdata[i].num_root,&kdata[i].num_file_creations,&kdata[i].num_shells,&kdata[i].num_access_files,&kdata[i].num_outbound_cmds,&kdata[i].is_host_login,&kdata[i].is_guest_login,&kdata[i].count,&kdata[i].srv_count); //作用同上


		fscanf(fp,"%f,%f,%f,%f,%f,%f,%f,%d,%d,%f,%f,%f,%f,%f,%f,%f,%f,",&kdata[i].serror_rate,&kdata[i].srv_serror_rate,&kdata[i].rerror_rate,&kdata[i].srv_rerror_rate,&kdata[i].same_srv_rate,&kdata[i].diff_srv_rate,&kdata[i].srv_diff_host_rate,&kdata[i].dst_host_count,&kdata[i].dst_host_srv_count,&kdata[i].dst_host_same_srv_rate,&kdata[i].dst_host_diff_srv_rate,&kdata[i].dst_host_same_src_port_rate,&kdata[i].dst_host_srv_diff_host_rate,&kdata[i].dst_host_serror_rate,&kdata[i].dst_host_srv_serror_rate,&kdata[i].dst_host_rerror_rate,&kdata[i].dst_host_srv_rerror_rate);


	fscanf(fp,"%c",&ch); //作用得到新字符
	j=0;
	while (ch!='.') 
	{
		kdata[i].idstype[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);

	}
	kdata[i].idstype[j]='\0';

		fscanf(fp,"%c",&ch);


	i++; //統計 KUPDATA的數據量

}

	normalcount=i;//總的NORMAL的KUPDATA的數據量

	fclose(fp); //關閉文件


	
	if((fp=fopen("attack.txt","r"))==NULL) 
		printf("can not open file\n"); 
	i=0;
	while(!feof(fp)) //文件輸入到KDDCUP數據結構中
	{
		fscanf(fp,"%d",&ddata[i].duration);

		fscanf(fp,"%c",&ch); //得到TXT文件中的,號

		fscanf(fp,"%c",&ch); //得到TXT文件中的,和,間的字符串
		j=0;
	while (ch!=','&&ch!='\n') 
	{
		ddata[i].protocol_type[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);
	}
		ddata[i].protocol_type[j]='\0'; //寫入字符串結束標志


	fscanf(fp,"%c",&ch); //作用同上
	j=0;
	while (ch!=',') 
	{
		ddata[i].service[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);
	//	printf("%c\n",ch);
	}
	ddata[i].service[j]='\0';

	fscanf(fp,"%c",&ch); //作用同上
	j=0;
	while (ch!=',') 
	{
		ddata[i].flag[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);

	}
	ddata[i].flag[j]='\0';


		fscanf(fp,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,",&ddata[i].src_bytes,&ddata[i].dst_bytes,&ddata[i].land,&ddata[i].wrong_fragment,&ddata[i].urgent,&ddata[i].hot,&ddata[i].num_failed_logins,&ddata[i].logged_in,&ddata[i].num_compromised,&ddata[i].root_shell,&ddata[i].su_attempted,&ddata[i].num_root,&ddata[i].num_file_creations,&ddata[i].num_shells,&ddata[i].num_access_files,&ddata[i].num_outbound_cmds,&ddata[i].is_host_login,&ddata[i].is_guest_login,&ddata[i].count,&ddata[i].srv_count); //作用同上


		fscanf(fp,"%f,%f,%f,%f,%f,%f,%f,%d,%d,%f,%f,%f,%f,%f,%f,%f,%f,",&ddata[i].serror_rate,&ddata[i].srv_serror_rate,&ddata[i].rerror_rate,&ddata[i].srv_rerror_rate,&ddata[i].same_srv_rate,&ddata[i].diff_srv_rate,&ddata[i].srv_diff_host_rate,&ddata[i].dst_host_count,&ddata[i].dst_host_srv_count,&ddata[i].dst_host_same_srv_rate,&ddata[i].dst_host_diff_srv_rate,&ddata[i].dst_host_same_src_port_rate,&ddata[i].dst_host_srv_diff_host_rate,&ddata[i].dst_host_serror_rate,&ddata[i].dst_host_srv_serror_rate,&ddata[i].dst_host_rerror_rate,&ddata[i].dst_host_srv_rerror_rate);


	fscanf(fp,"%c",&ch); //作用得到新字符
	j=0;
	while (ch!='.') 
	{
		ddata[i].idstype[j]=ch;
		j++;
		fscanf(fp,"%c",&ch);

	}
	ddata[i].idstype[j]='\0';

		fscanf(fp,"%c",&ch);


	i++; //統計 KUPDATA的數據量

}

	attackcount=i;//總的attack的KUPDATA的數據量

	fclose(fp); //關閉文件
	printf("\n%d  %d\n",normalcount,attackcount);
	getchar();
	getchar();
}


void initpopulation() //初始化種群
{
	int i,t;
	srand((unsigned) time(NULL));

	for(i=0;i<POPSIZE;i++)
	{
		if((t=rand()%10)>8) 
		{
			population[i].duration=-1;//通配符 即什么都無所謂 在與KUPDATA匹配中跳過此項
		}
		else if(t<4)
			{
				population[i].duration=0;
			}
			else 
		population[i].duration=rand()%300;// 隨機初始化


		if((rand()%10)>8) 
		{
			population[i].protocol_type=-1;
		}
		else 
		{
			population[i].protocol_type=rand()%3;// 每一個數代表一種協議 0:TCP 1:UDP 2:ICMP
		}


		if((rand()%10)>8) 
		{
			population[i].service=-1;
		}
		else 
		{
			population[i].service=rand()%5;// 總結一下常用的52種服務
		}


		if(t=(rand()%10)>8) 
		{
			population[i].flag=-1;
		}

/*		else if (t<4)
		{
			population[i].flag=2; // SF 較為常見 
		}*/
		else 
		{
			population[i].flag=rand()%6; // 總結一下常用的6種 5:SF 4:SH 3:S1 2:S0 1:REJ 0:RSTO
		}
        

		if((rand()%10)>5)   // 0.1 的概率為通配符
		{
			population[i].src_bytes=-1;
		}
		else 
		{
			population[i].src_bytes=rand()%1500;
		}

		if((rand()%10)>5)   //0.1 的概率為通配符
		{
			population[i].dst_bytes=-1;
		}
		else 
		{
			population[i].dst_bytes=rand()%15000;
		}
    

		if((rand()%10)>8)   //0.1 的概率為通配符
		{
			population[i].land=-1;
		}
		else 
		{
			population[i].land=rand()%5;
		}	

		if((rand()%10)>8)   //0.1 的概率為通配符
		{
			population[i].wrong_fragment=-1;
		}
		else 
		{
			population[i].wrong_fragment=rand()%5;
		}	


	}
/*
printf("\n\nthis is population result:");

for(i = 0 ; i < POPSIZE ; i++)
{
	printf("\n%d,%d,%d,%d,%d,%d,%d,%d\n",population[i].duration,population[i].protocol_type,population[i].service,population[i].flag,population[i].src_bytes,population[i].dst_bytes,population[i].land,population[i].wrong_fragment);
}	
*/
}


void 	countfitness()
{
	int i,j,vcount;
	float ap,np; //ap 為此個體與攻擊文本匹配概率 ;np為此個體與正常文本匹配概率  fitness=ap-np  范圍 【-1,1】
	char tempstr[10];

	for(i=0;i<POPSIZE;i++)
	{
		/*  規則個體對正常文件匹配概率*/
		vcount=0;

		for (j=0;j<normalcount;j++)  // 統計染色體與正常文本normal的匹配個數,匹配概率
		{

             if (population[i].duration!=-1 && population[i].duration!=kdata[j].duration)
				 continue;  //continue控制跳出此次循環;j++后繼續 而break則跳出了for循環
			 if (population[i].protocol_type!=-1)
			 {
				 switch(population[i].protocol_type)
				 {
				   case 0 : strcpy(tempstr,"tcp");break;
				   case 1 : strcpy(tempstr,"udp");break;
				   case 2 : strcpy(tempstr,"icmp");break;
				 }
			    if (stringcmp(kdata[j].protocol_type,tempstr)!=0)
					 continue;

			 }

/* 在kddcup中總結出 有這么多SERVICE
http,private,smtp,finger,domain_u,eco_i,ntp_u,auth,ecr_i,telnet,ftp,other,
ftp_data,ssh,ldap,netbios_dgm,netbios_ns,netbios_ssn,imap4,sql_net,Z39_50,bgp,

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区在线播放| 亚洲女同ⅹxx女同tv| 国产精品久久精品日日| 午夜久久久影院| 国产在线国偷精品免费看| 99久久国产综合精品色伊| 欧美精品丝袜中出| 亚洲一区免费在线观看| 久久综合成人精品亚洲另类欧美| 国产亚洲va综合人人澡精品| 亚洲乱码国产乱码精品精小说 | 成人午夜免费视频| 欧美久久婷婷综合色| 成人免费一区二区三区视频| 韩国av一区二区三区四区 | 成人免费视频视频| 精品国产乱码久久久久久免费| 夜夜操天天操亚洲| 99久久er热在这里只有精品66| 制服丝袜成人动漫| 天堂va蜜桃一区二区三区| 色综合天天综合网国产成人综合天| 欧美日韩国产首页| 日韩激情视频在线观看| 99久久国产综合精品麻豆| 2024国产精品| 日本视频在线一区| 在线成人免费观看| 婷婷六月综合亚洲| 欧美日韩和欧美的一区二区| 亚洲一二三区不卡| 欧美亚日韩国产aⅴ精品中极品| 国产精品网站在线观看| 成人午夜电影小说| 国产精品成人午夜| 99re66热这里只有精品3直播 | 亚洲国产成人在线| 国产传媒欧美日韩成人| 国产欧美va欧美不卡在线| 成人污视频在线观看| 中文字幕一区在线| 欧洲中文字幕精品| 婷婷综合五月天| 日韩精品一区二区三区三区免费| 日本一不卡视频| 久久无码av三级| 懂色av一区二区夜夜嗨| 中文字幕一区在线| 欧美三级三级三级| 久久国产精品第一页| 久久久亚洲精品一区二区三区| 国产mv日韩mv欧美| 亚洲美女少妇撒尿| 91精品国产色综合久久| 国产主播一区二区三区| 国产精品久久精品日日| 精品视频一区二区三区免费| 五月综合激情日本mⅴ| 精品国产91乱码一区二区三区| 国产成人一区二区精品非洲| 亚洲人成人一区二区在线观看 | 在线不卡的av| 一区二区三区在线免费| 欧美亚洲高清一区| 精东粉嫩av免费一区二区三区| 久久精品人人做人人综合| 91视频.com| 免费在线一区观看| 中文字幕五月欧美| 69成人精品免费视频| 成熟亚洲日本毛茸茸凸凹| 亚洲与欧洲av电影| 久久天堂av综合合色蜜桃网| 91免费视频大全| 麻豆国产欧美一区二区三区| 国产精品1区2区| 一区二区三区在线视频播放| 精品国产污网站| www.99精品| 韩国精品在线观看| 亚洲高清免费在线| 亚洲视频一区二区在线观看| 99视频热这里只有精品免费| 蜜桃传媒麻豆第一区在线观看| 一区视频在线播放| 久久影院午夜论| 欧美老女人在线| 91色porny蝌蚪| 国产精品中文字幕欧美| 天天综合色天天| 亚洲欧美日韩中文字幕一区二区三区| 欧美哺乳videos| 3atv一区二区三区| 日本伦理一区二区| 不卡av电影在线播放| 国产自产视频一区二区三区| 日韩精品1区2区3区| 一区二区高清免费观看影视大全| 中文成人av在线| ww久久中文字幕| 日韩欧美一二三四区| 欧美日韩日本视频| 欧美性猛交xxxxxx富婆| 91性感美女视频| 色综合网色综合| 99精品一区二区| 99久久精品国产网站| 成人自拍视频在线观看| 国产精品一区免费在线观看| 蜜桃精品视频在线| 美腿丝袜在线亚洲一区| 日韩av中文字幕一区二区| 亚洲成av人片在线| 性欧美大战久久久久久久久| 夜夜嗨av一区二区三区网页 | 亚洲精品五月天| 国产精品成人免费精品自在线观看| 精品国产91乱码一区二区三区| 欧美mv日韩mv国产| 日韩欧美在线不卡| 久久欧美一区二区| 日本一区二区成人| 亚洲精品你懂的| 亚洲国产日韩一区二区| 日韩精品一级中文字幕精品视频免费观看| 亚洲国产一区二区视频| 婷婷一区二区三区| 久久精品国产色蜜蜜麻豆| 国产毛片一区二区| 99精品视频一区二区| 在线观看亚洲精品视频| 欧美久久一二区| 久久久亚洲精品石原莉奈 | 盗摄精品av一区二区三区| 成人av电影在线网| 色婷婷综合久久久| 欧美日免费三级在线| 欧美不卡视频一区| 国产精品久久久久久久久免费樱桃 | 国产日韩欧美激情| 中文字幕一区二区三区乱码在线| 亚洲精品综合在线| 免费不卡在线观看| 国产 日韩 欧美大片| 91农村精品一区二区在线| 欧美精品久久久久久久多人混战| 日韩欧美综合在线| 国产精品嫩草影院av蜜臀| 一二三区精品福利视频| 捆绑变态av一区二区三区| 国产精品影音先锋| 成人av在线看| 日韩三级中文字幕| 中文字幕在线观看一区二区| 亚洲成人自拍网| 国产不卡视频一区二区三区| 在线观看国产一区二区| 久久女同性恋中文字幕| 亚洲一区二区在线播放相泽| 欧美日韩色一区| 国产精品456露脸| 日本韩国欧美一区二区三区| 91精品国产综合久久久蜜臀粉嫩 | 中文字幕在线观看不卡| 无码av免费一区二区三区试看| 国内精品国产成人国产三级粉色| 91在线一区二区| 久久久久久久精| 丝袜诱惑亚洲看片| 精品国产凹凸成av人网站| 亚洲影院久久精品| 国产一区二区免费在线| 欧美精品久久一区| 一区二区免费在线| www.色综合.com| 久久久久国产精品厨房| 日韩av电影一区| 在线观看亚洲精品视频| 中文字幕国产一区二区| 久久精品99久久久| 色综合久久久久网| 91影视在线播放| www亚洲一区| 日韩电影一区二区三区| 91视频免费观看| 国产精品国产三级国产普通话蜜臀 | 亚洲欧美日韩系列| 国产ts人妖一区二区| 久久这里只有精品视频网| 婷婷成人激情在线网| 欧美无人高清视频在线观看| 亚洲欧洲一区二区三区| 国产v综合v亚洲欧| 国产女主播在线一区二区| 国产黄色精品网站| 久久综合狠狠综合久久激情| 激情偷乱视频一区二区三区| 91精品国产91久久综合桃花| 午夜电影一区二区三区| 欧美精品高清视频|