Skip to content

sivrity/Python_Scripting_Network_Program

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python_Scripting_Network_Program

Mailing Client

Certainly! A basic mailing client in Python involves utilizing libraries like smtplib and email for sending emails through an SMTP server. Here's a simplified description:

Steps to Create a Simple Mailing Client: Import Required Libraries:

smtplib: Provides an SMTP client session to send emails. email: Handles email content formatting. Establish Connection to SMTP Server:

Use smtplib.SMTP() to connect to the SMTP server:

import smtplib

smtp_server = smtplib.SMTP('smtp.example.com', 587)  # Replace with your SMTP server and port
smtp_server.starttls()  # Enable TLS encryption (if required)
smtp_server.login('your_email@example.com', 'your_password')

Create an Email Message:

Use the email library to compose an email message:

import email
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

message = MIMEMultipart()
message['From'] = 'your_email@example.com'
message['To'] = 'recipient@example.com'
message['Subject'] = 'Subject of the email'

body = 'Content of your email'
message.attach(MIMEText(body, 'plain'))
Send the Email:

Use smtp_server.sendmail() to send the email:

smtp_server.sendmail('your_email@example.com', 'recipient@example.com', message.as_string())

Close the Connection:

Close the SMTP connection:

smtp_server.quit()

Usage Note: Ensure you have the correct SMTP server address, port, email credentials, and appropriate permissions to access the SMTP server. Be cautious with authentication credentials; avoid hardcoding them directly into your code for security reasons. Enable secure connections (TLS/SSL) if required by your SMTP server. Customize the email's content, subject, sender, and recipient as needed. This example provides a basic structure for sending emails via SMTP using Python. For more advanced functionalities like attachments, HTML content, and additional headers, explore the capabilities offered by the email library and the SMTP protocol's features.

Port Scanner

A port scanning tool in Python allows you to discover open ports on a target machine or network. It leverages Python's socket library to create connections to different ports and determine whether they are open, closed, or filtered.

Here's a basic description of how you can create a simple port scanner using Python:

Using the socket Library: Import socket Module:

import socket

Define Function for Port Scanning:

def port_scan(target_ip, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)  # Set timeout for connection attempt

    try:
        result = sock.connect_ex((target_ip, port))
        if result == 0:
            print(f"Port {port} is open")
        else:
            print(f"Port {port} is closed")
    except socket.error as e:
        print(f"Error occurred: {e}")
    finally:
        sock.close()

Scan Ports:

Define the target IP address and a range of ports to scan. Iterate through the range and call the port_scan function for each port:

target_ip = '192.168.1.100'  # Replace with your target IP
ports_to_scan = range(1, 1025)  # Specify the range of ports to scan

for port in ports_to_scan:
    port_scan(target_ip, port)

Usage Note: The socket library is used to create TCP connections and check if the connection to a specific port is successful (connect_ex() method). The socket.AF_INET represents the address family (IPv4) and socket.SOCK_STREAM indicates the TCP socket type. Change the target_ip variable to the IP address you want to scan. The ports_to_scan variable specifies the range of ports to be scanned. You can modify this range according to your requirements. Note that performing port scanning on networks or systems without authorization may violate laws and regulations. Always ensure proper authorization before conducting any scanning.

Chat Room

Creating a chat room using Python's networking capabilities typically involves implementing a server-client architecture where multiple clients connect to a central server. Here's a simple example using Python's socket library:

Server Code:

Server Setup:

import socket
import threading

# Create a socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to a specific address and port
server_socket.bind(('localhost', 8888))  # Replace with your desired IP and port

# Listen for incoming connections
server_socket.listen()

# List to hold connected clients
clients = []

# Function to handle client connections
def handle_client(client_socket, client_address):
    while True:
        # Receive messages from the client
        message = client_socket.recv(1024).decode('utf-8')
        if message == 'quit':
            break

        # Broadcast the received message to all connected clients
        for client in clients:
            if client != client_socket:
                client.send(f'{client_address}: {message}'.encode('utf-8'))

    # Close the client connection
    client_socket.close()

# Accept incoming client connections
while True:
    client_socket, client_address = server_socket.accept()

    # Add the new client to the clients list
    clients.append(client_socket)

    # Start a new thread to handle the client
    thread = threading.Thread(target=handle_client, args=(client_socket, client_address))
    thread.start()

Client Code:

Client Setup:

import socket
import threading

# Create a socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect to the server
client_socket.connect(('localhost', 8888))  # Replace with the server's IP and port

# Function to send messages
def send_messages():
    while True:
        message = input()
        client_socket.send(message.encode('utf-8'))
        if message == 'quit':
            break

# Function to receive messages
def receive_messages():
    while True:
        message = client_socket.recv(1024).decode('utf-8')
        print(message)
        if message == 'quit':
            break

# Start send and receive threads
send_thread = threading.Thread(target=send_messages)
receive_thread = threading.Thread(target=receive_messages)

send_thread.start()
receive_thread.start()

Usage Note: The server listens for incoming connections and relays messages to all connected clients. Each client connects to the server and can send/receive messages asynchronously using threads. Clients can communicate by sending messages to the server, which then broadcasts the messages to all other connected clients. The keyword 'quit' can be used to exit the chat room.

DDoS python

Denial of Service (DoS) is a cyber-attack on an individual Computer or Website with the intent to deny services to intended users. Their purpose is to disrupt an organization’s network operations by denying access to its users. Denial of service is typically accomplished by flooding the targeted machine or resource with surplus requests in an attempt to overload systems and prevent some or all legitimate requests from being fulfilled. For example, if a bank website can handle 10 people a second by clicking the Login button, an attacker only has to send 10 fake requests per second to make it so no legitimate users can log in. DoS attacks exploit various weaknesses in computer network technologies. They may target servers, network routers, or network communication links. They can cause computers and routers to crash and links to bog down. The most famous DoS technique is the Ping of Death. The Ping of Death attack works by generating and sending special network messages (specifically, ICMP packets of non-standard sizes) that cause problems for systems that receive them. In the early days of the Web, this attack could cause unprotected Internet servers to crash quickly. It is strongly recommended to try all described activities on virtual machines rather than in your working environment.Following is the command for performing flooding of requests on an IP.

ping ip_address –t -65500

HERE,“ping” sends the data packets to the victim.“ip_address” is the IP address of the victim.“-t” means the data packets should be sent until the program is stopped.“-l(65500)” specifies the data load to be sent to the victim.Other basic types of DoS attacks involve.Flooding a network with useless activity so that genuine traffic cannot get through. The TCP/IP SYN and Smurf attacks are two common examples.Remotely overloading a system’s CPU so that valid requests cannot be processed.Changing permissions or breaking authorization logic to prevent users from logging into a system. One common example involves triggering a rapid series of false login attempts that lockout accounts from being able to log in.Deleting or interfering with specific critical applications or services to prevent their normal operation (even if the system and network overall are functional).Another variant of the DoS is the Smurf attack. This involves emails with automatic responses. If someone emails hundreds of email messages with a fake return email address to hundreds of people in an organization with an autoresponder on in their email, the initially sent messages can become thousands sent to the fake email address. If that fake email address belongs to someone, this can overwhelm that person’s account. DoS attacks can cause the following problems:Ineffective servicesInaccessible servicesInterruption of network trafficConnection interference

python ddos.py target_ip_address apache

About

Python Scripting Networking Programming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages