This MATLAB code reads in network traffic data from a file to perform anomaly detection. It performs the following steps:
1. Reads in the data file and parses the header and first line to determine the data format.
2. Loads all the data into memory in cell arrays for each column.
3. Prepares the data for display by concatenating cells and converts to numeric where possible.
4. Calculates statistics on the training data labels and each attribute column to understand the distribution of normal and anomalous values. These statistics are stored in separate cell arrays for each attribute.
5. Enables buttons to allow interacting with and visualizing the processed training data and statistics.
This MATLAB code reads in network traffic data from a file to perform anomaly detection. It performs the following steps:
1. Reads in the data file and parses the header and first line to determine the data format.
2. Loads all the data into memory in cell arrays for each column.
3. Prepares the data for display by concatenating cells and converts to numeric where possible.
4. Calculates statistics on the training data labels and each attribute column to understand the distribution of normal and anomalous values. These statistics are stored in separate cell arrays for each attribute.
5. Enables buttons to allow interacting with and visualizing the processed training data and statistics.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing % singleton*. % % H = UNTITLED returns the handle to a new UNTITLED or the handle to % the existing singleton*. % % UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in UNTITLED.M with the given input % arguments. % % UNTITLED('Property','Value',...) creates a new UNTITLED or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 04-Oct-2014 10:59:16
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible. function untitled_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled handles.output = hObject; dishasil; set(handles.pushbutton3,'Enable','off'); set(handles.pushbutton18,'Enable','off'); set(handles.pushbutton23,'Enable','off'); set(handles.pushbutton27,'Enable','off'); set(handles.pushbutton28,'Enable','off'); set(handles.pushbutton19,'Enable','off'); set(handles.pushbutton20,'Enable','off');
% UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = untitled_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %[numeric,txt,dataah]=xlsread('kddcup.xlsx',1,'a1:ap494022'); %dataah=csvread('kddcup.csv'); %set(handles.uitable1,'Data',dataah); % read the data set(handles.pushbutton1,'Enable','off'); set(handles.text1,'String','Please wait... read the data [kddcup.dat] (1/6)'); pause(0.1); [fid, message] = fopen('kddcup.dat'); if (fid == -1) error(message); end set(handles.text1,'String','Please wait... reads line without end of line character (2/6)'); pause(0.1); header_line = fgetl(fid); % reads line without end of line character data_start_position = ftell(fid); names = regexp(header_line, '\S*', 'match');
% now try parsing the first data line set(handles.text1,'String','Please wait... now try parsing the first data line (3/6)'); pause(0.1); test_line = fgetl(fid); test_data = regexp(test_line, '\S*', 'match'); format_str = ''; all_numbers = 1; num_cols = length(test_data); for i = 1: num_cols match = regexp(test_data{i}, '([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+- ]?\d+))?', 'match'); if isempty(match) format_str = [format_str '%s']; all_numbers = 0; else format_str = [format_str '%f']; end end
% now read the data in the file for real set(handles.text1,'String','Please wait... now read the data in the file for real (4/6)'); pause(0.1); fseek(fid, data_start_position, 'bof'); if all_numbers == 0 data = textscan(fid, format_str); else raw_data = fread(fid,'uint8=>char'); data_array = reshape(sscanf(raw_data, format_str), num_cols, []); data = {}; for i = 1: num_cols data{i} = data_array(i, :)'; end end set(handles.text1,'String','Please wait... close file (5/6)'); pause(0.1); fclose(fid); set(handles.text1,'String','Please wait... prepare data composition (6/6)'); pause(0.01); tempdata=horzcat(num2cell(data{1,1}),data{1,2},data{1,3},num2cell(data{1,4}), num2cell(data{1,5}),num2cell(data{1,6}),num2cell(data{1,7}),num2cell(data{1,8 })...
% --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data1 global data2 global data3 global data4 global data5 global data6 global data7 global data8 global data9 global data10 global data11 global data12 global tempdata
dishasil; tempdata=get(handles.uitable2,'Data'); %training label set(handles.text1,'String','Please wait... process training label...'); pause(0.1); A=tempdata(:,12); [jumtot,auah]=size(A); [i,j]=ind2sub(size(A), strmatch('normal', A, 'exact')); [jumnormal,auah]=size(i); jumanomali=jumtot-jumnormal; data12{1,1}='Normal'; data12{1,2}=jumnormal; data12{1,3}=jumtot; data12{1,4}=jumnormal/jumtot; data12{2,1}='Anomali'; data12{2,2}=jumanomali; data12{2,3}=jumtot; data12{2,4}=jumanomali/jumtot; set(handles.pushbutton16,'Enable','on'); %training Duration set(handles.text1,'String','Please wait... process training duration...'); pause(0.1); A=tempdata(:,1); [jumtot,auah]=size(A); tempkriteria={'0-255';'255-512';'512-1024';'>1024'}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar if v==1 u=A(cell2mat(A)<255); [jumvar,auah]=size(u); B=tempdata(i,1); u=B(cell2mat(B)<255); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=0; jumvar2=255; end if v==2 u=A(cell2mat(A)>=255 & cell2mat(A)<512); [jumvar,auah]=size(u); B=tempdata(i,1); u=B(cell2mat(B)>=255 & cell2mat(B)<512); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=255; jumvar2=512; end if v==3 u=A(cell2mat(A)>=512 & cell2mat(A)<1024); [jumvar,auah]=size(u); B=tempdata(i,1); u=B(cell2mat(B)>=512 & cell2mat(B)<1024); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=512; jumvar2=1024; end if v==4 u=A(cell2mat(A)>=1024); [jumvar,auah]=size(u); B=tempdata(i,1); u=B(cell2mat(B)>=1024); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=1024; jumvar2=1000000000; end data1{z,1}=tempkriteria{v}; data1{z,2}=jumvar1; data1{z,3}=jumvar2; data1{z,4}=jumnormalvar; data1{z,5}=jumtot; data1{z,6}=jumnormalvar/jumtot; data1{z,7}='Normal'; z=z+1; data1{z,1}=tempkriteria{v}; data1{z,2}=jumvar1; data1{z,3}=jumvar2; data1{z,4}=jumanomalivar; data1{z,5}=jumtot; data1{z,6}=jumanomalivar/jumtot; data1{z,7}='Anomali'; z=z+1; end set(handles.pushbutton5,'Enable','on'); %training protocol_type set(handles.text1,'String','Please wait... process training protocol_type...'); pause(0.1); A=tempdata(:,2); [jumtot,auah]=size(A); tempkriteria={'tcp';'udp';'icmp'}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar [u,j]=ind2sub(size(A), strmatch(tempkriteria{v}, A, 'exact')); [jumvar,auah]=size(u); B=tempdata(i,2); [u,j]=ind2sub(size(B), strmatch(tempkriteria{v}, B, 'exact')); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data2{z,1}=tempkriteria{v}; data2{z,2}=jumnormalvar; data2{z,3}=jumtot; data2{z,4}=jumnormalvar/jumtot; data2{z,5}='Normal'; z=z+1; data2{z,1}=tempkriteria{v}; data2{z,2}=jumanomalivar; data2{z,3}=jumtot; data2{z,4}=jumanomalivar/jumtot; data2{z,5}='Anomali'; z=z+1; end set(handles.pushbutton6,'Enable','on'); %training Service set(handles.text1,'String','Please wait... process training service...'); pause(0.1); A=tempdata(:,3); [jumtot,auah]=size(A); tempkriteria={'auth';'bgp';'courier';'csnet_ns';'ctf';'daytime';'discard';'do main';'domain_u';'echo';'eco_i';'ecr_i';'efs';'exec';'finger';'ftp';'ftp_data ';'gopher';'hostnames';'http';'http_443';'imap4';'IRC';'iso_tsap';'klogin';'k shell';'ldap';'link';'login';'mtp';'name';'netbios_dgm';'netbios_ns';'netbios _ssn';'netstat';'nnsp';'nntp';'ntp_u';'other';'pm_dump';'pop_2';'pop_3';'prin ter';'private';'red_i';'remote_job';'rje';'shell';'smtp';'sql_net';'ssh';'sun rpc';'supdup';'systat';'telnet';'tftp_u';'tim_i';'time';'urh_i';'urp_i';'uucp ';'uucp_path';'vmnet';'whois';'X11';'Z39_50'}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar [u,j]=ind2sub(size(A), strmatch(tempkriteria{v}, A, 'exact')); [jumvar,auah]=size(u); B=tempdata(i,3); [u,j]=ind2sub(size(B), strmatch(tempkriteria{v}, B, 'exact')); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data3{z,1}=tempkriteria{v}; data3{z,2}=jumnormalvar; data3{z,3}=jumtot; data3{z,4}=jumnormalvar/jumtot; data3{z,5}='Normal'; z=z+1; data3{z,1}=tempkriteria{v}; data3{z,2}=jumanomalivar; data3{z,3}=jumtot; data3{z,4}=jumanomalivar/jumtot; data3{z,5}='Anomali'; z=z+1; end set(handles.pushbutton7,'Enable','on'); %src_bytes set(handles.text1,'String','Please wait... process training src_bytes...'); pause(0.1); A=tempdata(:,4); [jumtot,auah]=size(A); tempkriteria={'0-255';'255-512';'512-1024';'>1024'}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar if v==1 u=A(cell2mat(A)<255); [jumvar,auah]=size(u); B=tempdata(i,4); u=B(cell2mat(B)<255); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=0; jumvar2=255; end if v==2 u=A(cell2mat(A)>=255 & cell2mat(A)<512); [jumvar,auah]=size(u); B=tempdata(i,4); u=B(cell2mat(B)>=255 & cell2mat(B)<512); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=255; jumvar2=512; end if v==3 u=A(cell2mat(A)>=512 & cell2mat(A)<1024); [jumvar,auah]=size(u); B=tempdata(i,4); u=B(cell2mat(B)>=512 & cell2mat(B)<1024); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=512; jumvar2=1024; end if v==4 u=A(cell2mat(A)>=1024); [jumvar,auah]=size(u); B=tempdata(i,4); u=B(cell2mat(B)>=1024); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=1024; jumvar2=1000000000; end data4{z,1}=tempkriteria{v}; data4{z,2}=jumvar1; data4{z,3}=jumvar2; data4{z,4}=jumnormalvar; data4{z,5}=jumtot; data4{z,6}=jumnormalvar/jumtot; data4{z,7}='Normal'; z=z+1; data4{z,1}=tempkriteria{v}; data4{z,2}=jumvar1; data4{z,3}=jumvar2; data4{z,4}=jumanomalivar; data4{z,5}=jumtot; data4{z,6}=jumanomalivar/jumtot; data4{z,7}='Anomali'; z=z+1; end set(handles.pushbutton8,'Enable','on'); %dst_bytes set(handles.text1,'String','Please wait... process training dst_bytes...'); pause(0.1); A=tempdata(:,5); [jumtot,auah]=size(A); tempkriteria={'0-255';'255-512';'512-1024';'>1024'}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar if v==1 u=A(cell2mat(A)<255); [jumvar,auah]=size(u); B=tempdata(i,5); u=B(cell2mat(B)<255); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=0; jumvar2=255; end if v==2 u=A(cell2mat(A)>=255 & cell2mat(A)<512); [jumvar,auah]=size(u); B=tempdata(i,5); u=B(cell2mat(B)>=255 & cell2mat(B)<512); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=255; jumvar2=512; end if v==3 u=A(cell2mat(A)>=512 & cell2mat(A)<1024); [jumvar,auah]=size(u); B=tempdata(i,5); u=B(cell2mat(B)>=512 & cell2mat(B)<1024); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=512; jumvar2=1024; end if v==4 u=A(cell2mat(A)>=1024); [jumvar,auah]=size(u); B=tempdata(i,5); u=B(cell2mat(B)>=1024); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; jumvar1=1024; jumvar2=1000000000; end data5{z,1}=tempkriteria{v}; data5{z,2}=jumvar1; data5{z,3}=jumvar2; data5{z,4}=jumnormalvar; data5{z,5}=jumtot; data5{z,6}=jumnormalvar/jumtot; data5{z,7}='Normal'; z=z+1; data5{z,1}=tempkriteria{v}; data5{z,2}=jumvar1; data5{z,3}=jumvar2; data5{z,4}=jumanomalivar; data5{z,5}=jumtot; data5{z,6}=jumanomalivar/jumtot; data5{z,7}='Anomali'; z=z+1; end set(handles.pushbutton9,'Enable','on'); %hot set(handles.text1,'String','Please wait... process training hot...'); pause(0.1); A=tempdata(:,6); [jumtot,auah]=size(A); tempkriteria={0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;2 4;25;26;27;28;29;30}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar u=cell2mat(A)==cell2mat(tempkriteria(v)); u=A(u); [jumvar,auah]=size(u); B=tempdata(i,6); u=cell2mat(B)==cell2mat(tempkriteria(v)); u=B(u); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data6{z,1}=tempkriteria{v}; data6{z,2}=jumnormalvar; data6{z,3}=jumtot; data6{z,4}=jumnormalvar/jumtot; data6{z,5}='Normal'; z=z+1; data6{z,1}=tempkriteria{v}; data6{z,2}=jumanomalivar; data6{z,3}=jumtot; data6{z,4}=jumanomalivar/jumtot; data6{z,5}='Anomali'; z=z+1; end set(handles.pushbutton10,'Enable','on'); %logged_in set(handles.text1,'String','Please wait... process training logged_in...'); pause(0.1); A=tempdata(:,7); [jumtot,auah]=size(A); tempkriteria={0;1}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar u=cell2mat(A)==cell2mat(tempkriteria(v)); u=A(u); [jumvar,auah]=size(u); B=tempdata(i,7); u=cell2mat(B)==cell2mat(tempkriteria(v)); u=B(u); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data7{z,1}=tempkriteria{v}; data7{z,2}=jumnormalvar; data7{z,3}=jumtot; data7{z,4}=jumnormalvar/jumtot; data7{z,5}='Normal'; z=z+1; data7{z,1}=tempkriteria{v}; data7{z,2}=jumanomalivar; data7{z,3}=jumtot; data7{z,4}=jumanomalivar/jumtot; data7{z,5}='Anomali'; z=z+1; end set(handles.pushbutton11,'Enable','on'); %num_root set(handles.text1,'String','Please wait... process training num_root...'); pause(0.1); A=tempdata(:,8); [jumtot,auah]=size(A); tempkriteria={0;1;2;3;4;5;6}; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar u=cell2mat(A)==cell2mat(tempkriteria(v)); u=A(u); [jumvar,auah]=size(u); B=tempdata(i,8); u=cell2mat(B)==cell2mat(tempkriteria(v)); u=B(u); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data8{z,1}=tempkriteria{v}; data8{z,2}=jumnormalvar; data8{z,3}=jumtot; data8{z,4}=jumnormalvar/jumtot; data8{z,5}='Normal'; z=z+1; data8{z,1}=tempkriteria{v}; data8{z,2}=jumanomalivar; data8{z,3}=jumtot; data8{z,4}=jumanomalivar/jumtot; data8{z,5}='Anomali'; z=z+1; end set(handles.pushbutton12,'Enable','on'); %Count set(handles.text1,'String','Please wait... process training Count...'); pause(0.1); A=tempdata(:,9); [jumtot,auah]=size(A); tempkriteria=[0:511]; tempkriteria=num2cell(tempkriteria)'; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar u=cell2mat(A)==cell2mat(tempkriteria(v)); u=A(u); [jumvar,auah]=size(u); B=tempdata(i,9); u=cell2mat(B)==cell2mat(tempkriteria(v)); u=B(u); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data9{z,1}=tempkriteria{v}; data9{z,2}=jumnormalvar; data9{z,3}=jumtot; data9{z,4}=jumnormalvar/jumtot; data9{z,5}='Normal'; z=z+1; data9{z,1}=tempkriteria{v}; data9{z,2}=jumanomalivar; data9{z,3}=jumtot; data9{z,4}=jumanomalivar/jumtot; data9{z,5}='Anomali'; z=z+1; end set(handles.pushbutton13,'Enable','on'); %dst_host_count set(handles.text1,'String','Please wait... process training dst_host_count...'); pause(0.1); A=tempdata(:,10); [jumtot,auah]=size(A); tempkriteria=[0:255]; tempkriteria=num2cell(tempkriteria)'; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar u=cell2mat(A)==cell2mat(tempkriteria(v)); u=A(u); [jumvar,auah]=size(u); B=tempdata(i,10); u=cell2mat(B)==cell2mat(tempkriteria(v)); u=B(u); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data10{z,1}=tempkriteria{v}; data10{z,2}=jumnormalvar; data10{z,3}=jumtot; data10{z,4}=jumnormalvar/jumtot; data10{z,5}='Normal'; z=z+1; data10{z,1}=tempkriteria{v}; data10{z,2}=jumanomalivar; data10{z,3}=jumtot; data10{z,4}=jumanomalivar/jumtot; data10{z,5}='Anomali'; z=z+1; end set(handles.pushbutton14,'Enable','on'); %dst_host_diff_srv_rate set(handles.text1,'String','Please wait... process training dst_host_diff_srv_rate...'); pause(0.1); A=tempdata(:,11); [jumtot,auah]=size(A); tempkriteria=[0:0.01:1]; tempkriteria=num2cell(tempkriteria)'; [jumbar,jumkol]=size(tempkriteria); z=1; for v=1:jumbar u=cell2mat(A)==cell2mat(tempkriteria(v)); u=A(u); [jumvar,auah]=size(u); B=tempdata(i,11); u=cell2mat(B)==cell2mat(tempkriteria(v)); u=B(u); [jumnormalvar,auah]=size(u); jumanomalivar=jumvar-jumnormalvar; data11{z,1}=tempkriteria{v}; data11{z,2}=jumnormalvar; data11{z,3}=jumtot; data11{z,4}=jumnormalvar/jumtot; data11{z,5}='Normal'; z=z+1; data11{z,1}=tempkriteria{v}; data11{z,2}=jumanomalivar; data11{z,3}=jumtot; data11{z,4}=jumanomalivar/jumtot; data11{z,5}='Anomali'; z=z+1; end set(handles.text1,'String','Ready...'); pause(0.1); set(handles.pushbutton4,'Enable','on'); set(handles.pushbutton15,'Enable','on'); set(handles.pushbutton18,'Enable','on'); set(handles.pushbutton21,'Enable','on');
% --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global tempdata tempdata=get(handles.uitable2,'Data'); set(handles.text0,'String','Data Training'); pause(0.1); set(handles.uitable1, 'ColumnName', {'Duration', 'protocol_type', 'Service', 'src_bytes', 'dst_bytes', 'Hot', 'logged_in', 'num_root', 'Count', 'dst_host_count', 'dst_host_diff_srv_rate', 'LABEL'}); set(handles.uitable1,'Data',tempdata);
% --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data1 set(handles.text0,'String','Data Training DURATION'); pause(0.1); set(handles.uitable1, 'ColumnName', {'DURATION', 'MIN', 'MAX', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data1);
% --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data2 set(handles.text0,'String','Data Training PROTOCOL_TYPE'); pause(0.1); set(handles.uitable1, 'ColumnName', {'PROTOCOL_TYPE', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data2);
% --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data3 set(handles.text0,'String','Data Training SERVICE'); pause(0.1); set(handles.uitable1, 'ColumnName', {'SERVICE', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data3);
% --- Executes on button press in pushbutton8. function pushbutton8_Callback(hObject, eventdata, handles) % hObject handle to pushbutton8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data4 set(handles.text0,'String','Data Training SRC_BYTES'); pause(0.1); set(handles.uitable1, 'ColumnName', {'SRC_BYTES', 'MIN', 'MAX', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data4);
% --- Executes on button press in pushbutton9. function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data5 set(handles.text0,'String','Data Training DST_BYTES'); pause(0.1); set(handles.uitable1, 'ColumnName', {'DST_BYTES', 'MIN', 'MAX', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data5);
% --- Executes on button press in pushbutton10. function pushbutton10_Callback(hObject, eventdata, handles) % hObject handle to pushbutton10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data6 set(handles.text0,'String','Data Training HOT'); pause(0.1); set(handles.uitable1, 'ColumnName', {'HOT', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data6);
% --- Executes on button press in pushbutton11. function pushbutton11_Callback(hObject, eventdata, handles) % hObject handle to pushbutton11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data7 set(handles.text0,'String','Data Training LOGGED_IN'); pause(0.1); set(handles.uitable1, 'ColumnName', {'LOGGED_IN', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data7);
% --- Executes on button press in pushbutton12. function pushbutton12_Callback(hObject, eventdata, handles) % hObject handle to pushbutton12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data8 set(handles.text0,'String','Data Training NUM_ROOT'); pause(0.1); set(handles.uitable1, 'ColumnName', {'NUM_ROOT', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data8);
% --- Executes on button press in pushbutton13. function pushbutton13_Callback(hObject, eventdata, handles) % hObject handle to pushbutton13 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data9 set(handles.text0,'String','Data Training COUNT'); pause(0.1); set(handles.uitable1, 'ColumnName', {'COUNT', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data9);
% --- Executes on button press in pushbutton14. function pushbutton14_Callback(hObject, eventdata, handles) % hObject handle to pushbutton14 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data10 set(handles.text0,'String','Data Training DST_HOST_COUNT'); pause(0.1); set(handles.uitable1, 'ColumnName', {'DST_HOST_COUNT', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data10);
% --- Executes on button press in pushbutton15. function pushbutton15_Callback(hObject, eventdata, handles) % hObject handle to pushbutton15 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data11 set(handles.text0,'String','Data Training DST_HOST_DIFF_SRV_RATE'); pause(0.1); set(handles.uitable1, 'ColumnName', {'DST_HOST_DIFF_SRV_RATE', 'JUMLAH', 'TOTAL', 'PELUANG', 'LABEL'}); set(handles.uitable1,'Data',data11);
% --- Executes on button press in pushbutton16. function pushbutton16_Callback(hObject, eventdata, handles) % hObject handle to pushbutton16 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data12 set(handles.text0,'String','Data Training LABEL'); pause(0.1); set(handles.uitable1, 'ColumnName', {'LABEL', 'JUMLAH', 'TOTAL', 'PELUANG'}); set(handles.uitable1,'Data',data12);
% --- Executes on button press in pushbutton17. function pushbutton17_Callback(hObject, eventdata, handles) % hObject handle to pushbutton17 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) judul=get(handles.text0,'String'); set(handles.text1,'String',strcat('Please wait... export data to...[',judul,'.xls]')); pause(0.1); xlswrite(strcat(judul,'.xls'),get(handles.uitable1,'Data')); set(handles.text1,'String','Ready...');
% --- Executes on button press in pushbutton18. function pushbutton18_Callback(hObject, eventdata, handles) % hObject handle to pushbutton18 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global datauji set(handles.text0,'String','Data Simulasi'); pause(0.1); set(handles.text1,'String','Please wait... load data simulasi [datauji.xlsx]...'); pause(0.1); [numeric,txt,datauji]=xlsread('datauji.xlsx',1,'a1:k4'); set(handles.uitable1, 'ColumnName', {'Duration', 'protocol_type', 'Service', 'src_bytes', 'dst_bytes', 'Hot', 'logged_in', 'num_root', 'Count', 'dst_host_count', 'dst_host_diff_srv_rate'}); set(handles.uitable1,'Data',datauji); set(handles.pushbutton23,'Enable','on'); set(handles.pushbutton27,'Enable','on'); set(handles.pushbutton28,'Enable','off'); set(handles.text1,'String','Ready...');
% --- Executes on button press in pushbutton19. function pushbutton19_Callback(hObject, eventdata, handles) % hObject handle to pushbutton19 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global P set(handles.text0,'String','Data Hasil Deteksi'); pause(0.1); set(handles.text1,'String','Please wait... load data hasil deteksi...'); pause(0.1); set(handles.uitable1, 'ColumnName', {'P-Normal', 'P-Anomali', 'Deteksi'}); set(handles.uitable1,'Data',P(:,36:38)); set(handles.text1,'String','Ready...');
% --- Executes on button press in pushbutton20. function pushbutton20_Callback(hObject, eventdata, handles) % hObject handle to pushbutton20 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global P set(handles.text0,'String','Data Peluang Anomali'); pause(0.1); set(handles.text1,'String','Please wait... load data peluang anomali...'); pause(0.1); set(handles.uitable1, 'ColumnName', {'Duration', 'protocol_type', 'Service', 'src_bytes', 'dst_bytes', 'Hot', 'logged_in', 'num_root', 'Count', 'dst_host_count', 'dst_host_diff_srv_rate', 'Anomali'}); set(handles.uitable1,'Data',P(:,[23:33 35])); set(handles.text1,'String','Ready...');
% --- Executes on button press in pushbutton21. function pushbutton21_Callback(hObject, eventdata, handles) % hObject handle to pushbutton21 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data1 global data2 global data3 global data4 global data5 global data6 global data7 global data8 global data9 global data10 global data11 global data12 global tempdata set(handles.text1,'String','Please wait...save parameter...'); pause(0.1); namafile='parameter'; save(strcat(namafile,'.mat'),'data1','data2','data3','data4','data5','data6', 'data7','data8','data9','data10','data11','data12'); set(handles.text1,'String','Please wait...save rawdata...'); pause(0.1); save('rawdata.mat','tempdata'); set(handles.text1,'String','Ready...');
% --- Executes on button press in pushbutton22. function pushbutton22_Callback(hObject, eventdata, handles) % hObject handle to pushbutton22 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data1 global data2 global data3 global data4 global data5 global data6 global data7 global data8 global data9 global data10 global data11 global data12 global tempdata set(handles.text1,'String','Please wait... load parameter...'); pause(0.1); load('parameter.mat'); enahasil; set(handles.pushbutton4,'Enable','on'); set(handles.uitable1, 'ColumnName', {'Duration', 'protocol_type', 'Service', 'src_bytes', 'dst_bytes', 'Hot', 'logged_in', 'num_root', 'Count', 'dst_host_count', 'dst_host_diff_srv_rate', 'LABEL'}); set(handles.uitable1,'Data',tempdata); set(handles.uitable2,'Data',tempdata); set(handles.text1,'String','Ready...');
% --- Executes on button press in pushbutton23. function pushbutton23_Callback(hObject, eventdata, handles) % hObject handle to pushbutton23 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global data1 global data2 global data3 global data4 global data5 global data6 global data7 global data8 global data9 global data10 global data11 global data12 global datauji global P
boolnya=data1; A=boolnya(:,7); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,6); u=B(cell2mat(tesnya(1))>=cell2mat(boolnya(i,2)) & cell2mat(tesnya(1))<cell2mat(boolnya(i,3))); hasil1{z,1}=cell2mat(u); z=z+1; end %hasil1 boolnya=data2; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); C=boolnya(i,1); [u,j]=ind2sub(size(C), strmatch(tesnya(2), C, 'exact')); hasil2{z,1}=cell2mat(B(u,1)); z=z+1; end %hasil2 boolnya=data3; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); C=boolnya(i,1); [u,j]=ind2sub(size(C), strmatch(tesnya(3), C, 'exact')); hasil3{z,1}=cell2mat(B(u,1)); z=z+1; end %hasil3 boolnya=data4; A=boolnya(:,7); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,6); u=B(cell2mat(tesnya(4))>=cell2mat(boolnya(i,2)) & cell2mat(tesnya(4))<cell2mat(boolnya(i,3))); hasil4{z,1}=cell2mat(u); z=z+1; end %hasil4 boolnya=data5; A=boolnya(:,7); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,6); u=B(cell2mat(tesnya(5))>=cell2mat(boolnya(i,2)) & cell2mat(tesnya(5))<cell2mat(boolnya(i,3))); hasil5{z,1}=cell2mat(u); z=z+1; end %hasil5 boolnya=data6; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); u=B(cell2mat(tesnya(6))==cell2mat(boolnya(i,1))); hasil6{z,1}=cell2mat(u); z=z+1; end %hasil6 boolnya=data7; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); u=B(cell2mat(tesnya(7))==cell2mat(boolnya(i,1))); hasil7{z,1}=cell2mat(u); z=z+1; end %hasil7 boolnya=data8; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); u=B(cell2mat(tesnya(8))==cell2mat(boolnya(i,1))); hasil8{z,1}=cell2mat(u); z=z+1; end %hasil8 boolnya=data9; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); u=B(cell2mat(tesnya(9))==cell2mat(boolnya(i,1))); hasil9{z,1}=cell2mat(u); z=z+1; end %hasil9 boolnya=data10; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); u=B(cell2mat(tesnya(10))==cell2mat(boolnya(i,1))); hasil10{z,1}=cell2mat(u); z=z+1; end %hasil10 boolnya=data11; A=boolnya(:,5); z=1; coba=data12(:,1); [jumbar,auah]=size(coba); for k=1:jumbar [i,j]=ind2sub(size(A), strmatch(coba{k}, A, 'exact')); B=boolnya(i,4); u=B(str2double(tesnya{11})==cell2mat(boolnya(i,1))); hasil11{z,1}=cell2mat(u); z=z+1; end %hasil11 P{w,1}=cell2mat(tesnya(1)); tesau=tesnya(2); P{w,2}=tesau{1}; tesau=tesnya(3); P{w,3}=tesau{1}; P{w,4}=cell2mat(tesnya(4)); P{w,5}=cell2mat(tesnya(5)); P{w,6}=cell2mat(tesnya(6)); P{w,7}=cell2mat(tesnya(7)); P{w,8}=cell2mat(tesnya(8)); P{w,9}=cell2mat(tesnya(9)); P{w,10}=cell2mat(tesnya(10)); P{w,11}=cell2mat(tesnya(11)); P{w,12}=cell2mat(hasil1(1,1)); P{w,13}=cell2mat(hasil2(1,1)); P{w,14}=cell2mat(hasil3(1,1)); P{w,15}=cell2mat(hasil4(1,1)); P{w,16}=cell2mat(hasil5(1,1)); P{w,17}=cell2mat(hasil6(1,1)); P{w,18}=cell2mat(hasil7(1,1)); P{w,19}=cell2mat(hasil8(1,1)); P{w,20}=cell2mat(hasil9(1,1)); P{w,21}=cell2mat(hasil10(1,1)); P{w,22}=cell2mat(hasil11(1,1)); P{w,23}=cell2mat(hasil1(2,1)); P{w,24}=cell2mat(hasil2(2,1)); P{w,25}=cell2mat(hasil3(2,1)); P{w,26}=cell2mat(hasil4(2,1)); P{w,27}=cell2mat(hasil5(2,1)); P{w,28}=cell2mat(hasil6(2,1)); P{w,29}=cell2mat(hasil7(2,1)); P{w,30}=cell2mat(hasil8(2,1)); P{w,31}=cell2mat(hasil9(2,1)); P{w,32}=cell2mat(hasil10(2,1)); P{w,33}=cell2mat(hasil11(2,1)); P{w,34}=cell2mat(data12(1,4)); P{w,35}=cell2mat(data12(2,4)); P{w,36}=1; for t=12:22 P{w,36}=cell2mat(P(w,36))*cell2mat(P(w,t)); end P{w,36}=cell2mat(P(w,36))*cell2mat(P(w,34)); P{w,37}=1; for t=23:33 P{w,37}=cell2mat(P(w,37))*cell2mat(P(w,t)); end P{w,37}=cell2mat(P(w,37))*cell2mat(P(w,35)); %P{w,38}=cell2mat(P(w,36))/(cell2mat(P(w,36))+cell2mat(P(w,37))); %P{w,39}=cell2mat(P(w,37))/(cell2mat(P(w,36))+cell2mat(P(w,37))); if cell2mat(P(w,36))>cell2mat(P(w,37)) P{w,38}='Normal'; else P{w,38}='Anomali'; end end set(handles.pushbutton27,'Enable','on'); set(handles.pushbutton28,'Enable','on'); set(handles.pushbutton19,'Enable','on'); set(handles.pushbutton20,'Enable','on');
% --- Executes on button press in pushbutton27. function pushbutton27_Callback(hObject, eventdata, handles) % hObject handle to pushbutton27 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global datauji set(handles.text0,'String','Data Simulasi'); pause(0.1); set(handles.text1,'String','Please wait... load data simulasi...'); pause(0.1); set(handles.uitable1, 'ColumnName', {'Duration', 'protocol_type', 'Service', 'src_bytes', 'dst_bytes', 'Hot', 'logged_in', 'num_root', 'Count', 'dst_host_count', 'dst_host_diff_srv_rate'}); set(handles.uitable1,'Data',datauji); set(handles.text1,'String','Ready...');
% --- Executes on button press in pushbutton28. function pushbutton28_Callback(hObject, eventdata, handles) % hObject handle to pushbutton28 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global P set(handles.text0,'String','Data Peluang Normal'); pause(0.1); set(handles.text1,'String','Please wait... load data peluang normal...'); pause(0.1); set(handles.uitable1, 'ColumnName', {'Duration', 'protocol_type', 'Service', 'src_bytes', 'dst_bytes', 'Hot', 'logged_in', 'num_root', 'Count', 'dst_host_count', 'dst_host_diff_srv_rate', 'Normal'}); set(handles.uitable1,'Data',P(:,[12:22 34])); set(handles.text1,'String','Ready...');