Need Help with outputs - New to Matlab
Need Help with outputs - New to Matlab
(OP)
hello,
i am trying to write a program in Matlab to generate psuedo-random ip's. i am having problems with the output funcions. it keeps putting out IP addresses that are not in the target range into my file. can anyone help me?
% N is the total # of IP adresses
% n is the total # of potential victims
% The target IP is a number between 1 and 16,777,215
% set to be 1
% M is the maximum # of iterations
% K is the number of trials
function [TargetInfectTime,VictimInfectTime] = IPsim(N,n,M,K)
TargetInfectTime=M*ones([1,K]);
infected=1;
VictimInfectTime=[];
address=[];
for j=1:K
for i=1:M
IP = ceil(N*rand(1,infected));
if sum(IP==1)>=1
TargetInfectTime=i; break
else if sum(IP<=(n+1))>=1
infected=infected+sum(IP<=(n+1));
VictimInfectTime=[VictimInfectTime i*ones(1,sum(IP<=(n+1)))];
address=[address IP];
end
end
end
results=fopen('results.txt','w');
fprintf(results,'Number of Machines Infected %10.0f\n',infected);
fprintf(results,'Target IP Infected %10.0f\n',TargetInfectTime);
fprintf(results,'Victim Infected %10.0f\n', VictimInfectTime);
fprintf(results,'IP Address %10.0f\n', address);
fclose(results)
end
end
i am trying to write a program in Matlab to generate psuedo-random ip's. i am having problems with the output funcions. it keeps putting out IP addresses that are not in the target range into my file. can anyone help me?
% N is the total # of IP adresses
% n is the total # of potential victims
% The target IP is a number between 1 and 16,777,215
% set to be 1
% M is the maximum # of iterations
% K is the number of trials
function [TargetInfectTime,VictimInfectTime] = IPsim(N,n,M,K)
TargetInfectTime=M*ones([1,K]);
infected=1;
VictimInfectTime=[];
address=[];
for j=1:K
for i=1:M
IP = ceil(N*rand(1,infected));
if sum(IP==1)>=1
TargetInfectTime=i; break
else if sum(IP<=(n+1))>=1
infected=infected+sum(IP<=(n+1));
VictimInfectTime=[VictimInfectTime i*ones(1,sum(IP<=(n+1)))];
address=[address IP];
end
end
end
results=fopen('results.txt','w');
fprintf(results,'Number of Machines Infected %10.0f\n',infected);
fprintf(results,'Target IP Infected %10.0f\n',TargetInfectTime);
fprintf(results,'Victim Infected %10.0f\n', VictimInfectTime);
fprintf(results,'IP Address %10.0f\n', address);
fclose(results)
end
end





RE: Need Help with outputs - New to Matlab
Additionally, you've given ZERO information about what you think you're supposed to be getting, and what you're actually getting.
TTFN
RE: Need Help with outputs - New to Matlab
What i am expecting to see is the IP address output when it is hit. the problem is it not only prints out the IP address less than n that caused it to enter the else if loop, it also prints out additional random IP addesses. there seems to be no pattern to why it is doing this. sometimes it prints out four or five additional IP addresses above the "n" value, other times it prints out 10 or more.
this is not an assignment for class, it is to further some research on random IP generation.
RE: Need Help with outputs - New to Matlab
TTFN
RE: Need Help with outputs - New to Matlab