Networking Lab
Source code
packets = {'Packet1', 'Packet2', 'Packet3'};
delay = 1; % seconds
for i = 1:length(packets)
fprintf('Transmitting %s...\n', packets{i});
pause(delay);
end
AIM. Write a program to check the simple IP Address Validator
Source code
ip = '192.168.1.10';
parts = str2double(strsplit(ip, '.'));
if length(parts)==4 && all(parts >= 0 & parts <= 255)
disp('Valid IP Address');
else
disp('Invalid IP Address');
end
AIM. Write a program to simulate Ping with Random Delay.
Source code
delay = rand() * 0.1; % Simulate delay in seconds
fprintf('Ping %d: delay = %.2f ms\n', i, delay*1000);
pause(1);
end
AIM: Write a program to implement a basic Port Scanner (on local host)
Source code
for port = 80:85
try
t = tcpclient(host, port, 'Timeout', 0.5);
fprintf('Port %d is open\n', port);
clear t
catch
fprintf('Port %d is closed\n', port);
end
end
AIM. Write a program to design a TCP/IP Client server model to transmit the data with delay.
Source code
% Server (Receiver)
disp('Server is listening...');
while true
if server.NumBytesAvailable > 0
data = read(server, server.NumBytesAvailable, "string");
disp(['Received: ', data]);
end
pause(0.1); % small delay to avoid busy waiting
end
Run below first:
% Client (Transmitter)
disp('Client connected to server');
messages = ["Hello", "This is test data", "With latency", "Goodbye"];
latency = 2; % Latency in seconds between packets
for i = 1:length(messages)
write(client, messages(i), "string");
disp(['Sent: ', messages(i)]);
pause(latency); % simulate delay
end
Stop-and-wait
clear;
for i = 1:5
fprintf("Sending Frame %d...\n", i);
if rand < 0.3
disp("ACK Lost! Retransmitting the same frame...");
i = i - 1;
else
disp("ACK Received.");
end
pause(0.5);
end
disp("All frames are sent successfully!");
Comments
Post a Comment