Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help with outputs - New to Matlab

Status
Not open for further replies.

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
 
Replies continue below

Recommended for you

Student posting is not allowed.

Additionally, you've given ZERO information about what you think you're supposed to be getting, and what you're actually getting.

TTFN



 
Sorry, i forgot to add what the issues were.

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.
 
Well, it looks to me like the results are consistent with your program, so you need to revisit what it is that you think your program is supposed to do.

TTFN



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor