A Bed Time Programming Test

A Bed Time Programming Test

For my CyberSecurity and Programming sides, I decided to see how quickly OpenAI's Model could generate a good-looking Python Application to Monitor My Network Traffic of any Process. It took 2 tries:

THIS IS FOR A MAC WINDOWS IS DIFFERENT - concerning TCL-TK/Tkinter - Can still be done though.

What I built in 2 seconds...

pip install psutil

brew install tcl-tk

This is the Application name it whatever.py and python3 or python name.py

import psutil
import tkinter as tk
from tkinter import ttk

# Function to update the process list


def update_processes():
    processes = []
    for proc in psutil.process_iter(['pid', 'name', 'cpu_percent', 'memory_percent']):
        try:
            # Fetch network connections for the process
            connections = proc.connections(kind='inet')
            if connections:  # Only proceed if there are network connections
                for conn in connections:
                    # Include only connections that are established
                    if conn.status == psutil.CONN_ESTABLISHED:
                        processes.append({
                            'pid': proc.info['pid'],
                            'name': proc.info['name'],
                            'cpu_percent': proc.info['cpu_percent'],
                            'memory_percent': proc.info['memory_percent'],
                            'local_addr': f"{conn.laddr.ip}:{conn.laddr.port}" if conn.laddr else 'N/A',
                            'remote_addr': f"{conn.raddr.ip}:{conn.raddr.port}" if conn.raddr else 'N/A',
                            'status': conn.status
                        })
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass  # Process might have ended or access was denied
    return processes

# Function to update the UI


def update_ui():
    for i in tree.get_children():
        tree.delete(i)  # Clear existing entries in the tree

    processes = update_processes()

    for proc in processes:
        tree.insert("", "end", values=(
            proc['pid'],
            proc['name'],
            proc['cpu_percent'],
            proc['memory_percent'],
            proc['local_addr'],
            proc['remote_addr'],
            proc['status']
        ))

    # Schedule the update every second
    root.after(1000, update_ui)


# Creating the main application window
root = tk.Tk()
root.title("Process Monitor with Network Usage")

# Setting the window size
root.geometry("1000x500")

# Creating the Treeview widget for displaying processes
columns = ("PID", "Name", "CPU Usage (%)", "Memory Usage (%)",
           "Local Address", "Remote Address", "Status")
tree = ttk.Treeview(root, columns=columns, show="headings")

# Define headings
tree.heading("PID", text="PID")
tree.heading("Name", text="Name")
tree.heading("CPU Usage (%)", text="CPU Usage (%)")
tree.heading("Memory Usage (%)", text="Memory Usage (%)")
tree.heading("Local Address", text="Local Address")
tree.heading("Remote Address", text="Remote Address")
tree.heading("Status", text="Status")

# Define column widths and anchor (text alignment)
tree.column("PID", width=50, anchor=tk.CENTER)
tree.column("Name", width=200, anchor=tk.W)
tree.column("CPU Usage (%)", width=100, anchor=tk.E)
tree.column("Memory Usage (%)", width=100, anchor=tk.E)
tree.column("Local Address", width=150, anchor=tk.W)
tree.column("Remote Address", width=150, anchor=tk.W)
tree.column("Status", width=100, anchor=tk.CENTER)

# Add lines between columns
style = ttk.Style()
# Raised appearance for headers
style.configure("Treeview.Heading", relief="raised")
style.configure("Treeview", rowheight=25, borderwidth=1,
                relief="solid", highlightthickness=1)

# Pack the treeview into the window
tree.pack(fill=tk.BOTH, expand=True)

# Start updating the UI in the main thread
root.after(1000, update_ui)

# Run the Tkinter main loop
root.mainloop()        

Thanks for sharing project

回复
Fabian Weber

?? Your vCISO & Auditor | ISO27001 | ?? Cloudsecurity | Compliance | We automate your security, you focus on your business ?? | Head of Compliance @ PCG (formerly WHYSEC)

4 个月

So no more developers needed? ??

回复
Waseem Aslam

Electrical Engineer | Growing Brands with Social Media & Affiliate Marketing | Business Growth Turning Ideas into Sales | Looking to Collaborate with Businesses | Let's Connect

4 个月

Awesome share

Rodolfo Parlati

Empowering Careers & Leaders | Professional Executive Coach | Leadership Trainer | Speaker?Helping You Achieve Promotions, Career Transitions & Leadership Success ? Top Future of Work Leader | Global Recognition Awarded

4 个月

Great journey, Aaron Lax. It's so impressive. And inspiring. Congrats!

Gratien Mukeshimana

?????????? ?????? ???????????? | ???????????????? | ????-?????????????? ???? 28 ?????? |???????? ???????????????????? ????????????????????| ?????? ?????? ???????????? ????????????????????

4 个月

Thank you for sharing

回复

要查看或添加评论,请登录

Aaron Lax的更多文章

  • The Quantum Leap - Recent Improvements

    The Quantum Leap - Recent Improvements

    Quantum computing has been making headlines for years, but two recent breakthroughs are pushing us closer than ever to…

    58 条评论
  • A Potential Integration of Technologies

    A Potential Integration of Technologies

    Imagine a future where we control microscopic robots. Inside our bodies with just our thoughts, enhancing our physical…

    68 条评论
  • 2025 and Beyond from a Tech POV

    2025 and Beyond from a Tech POV

    Recently, the world has witnessed a surge in formerly futuristic technologies entering today's market. Some notables…

    68 条评论
  • Who's Who 2024 Aaron Lax's Version

    Who's Who 2024 Aaron Lax's Version

    This is a newsletter being distributed as a method to bring awareness to the best of in their respective fields! These…

    107 条评论
  • Quantum Entanglement in Biology

    Quantum Entanglement in Biology

    Inspiring the Next Frontier in Quantum Computing and Medicine Quantum mechanics, a field traditionally associated with…

    67 条评论
  • The Integration of AI, Robotics, and Human =The Future of Precision Medicine

    The Integration of AI, Robotics, and Human =The Future of Precision Medicine

    Biotechnology’s rapid advancements over the past few decades, particularly in the areas of genetic engineering, drug…

    39 条评论
  • Understanding the LinkedIn Algorithm: Insights from the Algorithm Report

    Understanding the LinkedIn Algorithm: Insights from the Algorithm Report

    The LinkedIn landscape is constantly evolving, with its algorithm playing a pivotal role in determining the visibility…

    53 条评论
  • Leveraging AI and Python to Secure Your Network: A Centralized Approach

    Leveraging AI and Python to Secure Your Network: A Centralized Approach

    In an era where cyber threats are becoming increasingly sophisticated, organizations are constantly pressured to…

    37 条评论
  • Quantum Entanglement: In the Brain and it's Potentials

    Quantum Entanglement: In the Brain and it's Potentials

    In recent years, quantum mechanics has started to creep into conversations well beyond classical physics. With its…

    68 条评论
  • A Possible Convergence of Technologies

    A Possible Convergence of Technologies

    Rapid advancements in robotics, artificial intelligence (AI), and biotechnology have set the stage for a future where…

    42 条评论

社区洞察

其他会员也浏览了