xacxado
Computer
- Jan 18, 2007
- 3
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