×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Need Help with outputs - New to Matlab

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

RE: Need Help with outputs - New to Matlab

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



RE: Need Help with outputs - New to Matlab

(OP)
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.

RE: Need Help with outputs - New to Matlab

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



RE: Need Help with outputs - New to Matlab

(OP)
Thanks for the help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources