diff --git a/CNP/Wireshark/SMTP/mail-sender.py b/CNP/Wireshark/SMTP/mail-sender.py new file mode 100644 index 0000000..186f05e --- /dev/null +++ b/CNP/Wireshark/SMTP/mail-sender.py @@ -0,0 +1,14 @@ +import smtplib +from email.message import EmailMessage + +# the email message +msg = EmailMessage() +msg['Subject'] = 'CNP Assignment Email' +msg['From'] = 'aadit@example.com' +msg['To'] = 'shreyas@example.com' # used example.com just to not have a DNS error. +msg.set_content('Hello World. This is a message that is to be captured for the CNP FISAC II.') + +#SMTP server running on localhost on port 25 +with smtplib.SMTP('127.0.0.1', 25) as server: + server.set_debuglevel(1) # debug output to see the SMTP conversation (for dev log) + server.send_message(msg) diff --git a/CNP/Wireshark/SMTP/smtp-server.py b/CNP/Wireshark/SMTP/smtp-server.py new file mode 100644 index 0000000..1868743 --- /dev/null +++ b/CNP/Wireshark/SMTP/smtp-server.py @@ -0,0 +1,33 @@ +import asyncio +import uvloop +from aiosmtpd.controller import Controller + +# handler that just prints the message content +class PrintHandler: + async def handle_DATA(self, server, session, envelope): + print("Message from:", envelope.mail_from) + print("Recipients:", envelope.rcpt_tos) + print("Message data:") + print(envelope.content.decode('utf8', errors='replace')) + print("End of message") + # Respond with a success code + return '250 Message accepted for delivery' + +# uvloop for better performance +asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) + +def run_server(): + # SMTP server controller, binding to localhost on port 25 + controller = Controller(PrintHandler(), hostname='127.0.0.1', port=25) + controller.start() + print("SMTP server running on port 25. Press Ctrl+C to stop.") + try: + # Run forever + asyncio.get_event_loop().run_forever() + except KeyboardInterrupt: + pass + finally: + controller.stop() + +if __name__ == '__main__': + run_server() diff --git a/OS/C/Week8/aq1 b/OS/C/Week8/aq1 new file mode 100755 index 0000000..901915e Binary files /dev/null and b/OS/C/Week8/aq1 differ diff --git a/OS/C/Week8/aq1.c b/OS/C/Week8/aq1.c index e69de29..8b4318b 100644 --- a/OS/C/Week8/aq1.c +++ b/OS/C/Week8/aq1.c @@ -0,0 +1,95 @@ +#include + +// C program for Banker's Algorithm (Safety & Resource Request) +// Optimized for minimal code size (e.g., for writing on paper) + +int main() { + int p, r, i, j, k, pid, req_pid = -1; // p=procs, r=res; req_pid: -1=initial, >=0 processing req + printf("P R:"); scanf("%d%d", &p, &r); // Input num processes and resources + int av[r], max[p][r], al[p][r], nd[p][r], req[r]; // av=avail, al=alloc, nd=need + int w[r], fin[p], seq[p]; // w=work, fin=finish, seq=safe sequence + + // Input available, max, allocation matrices + printf("Av:"); for(j=0; j w[j]) { possible = 0; break; } + if(possible) { // If need <= work + for(k=0; k nd[pid][j]) { puts("Err:Req>Need"); goto end; } + // Check 2: Request <= Available + for(j=0; j av[j]) { puts("Wait:Req>Avail"); goto end; } + + // Tentatively allocate resources + for(j=0; j