Police arrest 20-year-old after Molotov cocktail thrown at Sam Altman’s San Francisco home
Back to Tutorials
techTutorialbeginner

Police arrest 20-year-old after Molotov cocktail thrown at Sam Altman’s San Francisco home

April 10, 202610 views4 min read

Learn to build basic network monitoring and website status checking tools using Python to enhance your digital security awareness.

Introduction

In today's world, understanding how to protect yourself and your digital assets is more important than ever. While the recent news about Sam Altman's home being targeted is concerning, it highlights the importance of cybersecurity awareness. This tutorial will teach you how to set up basic security monitoring using Python and simple network scanning techniques. These skills will help you understand how to monitor your own digital environment for potential threats.

Prerequisites

Before beginning this tutorial, you'll need:

  • A computer with Python installed (version 3.6 or higher)
  • Basic understanding of command-line interfaces
  • Internet connection
  • Python packages: scapy and requests

Step-by-Step Instructions

1. Install Required Python Packages

First, we need to install the necessary Python packages for network monitoring. Open your terminal or command prompt and run:

pip install scapy requests

Why this step? The scapy library allows us to craft and send network packets, while requests helps us make HTTP requests to check website status.

2. Create a Basic Network Scanner

Let's create a simple script that scans your local network for active devices. Create a new file called network_scanner.py and add the following code:

import scapy.all as scapy

def scan_network(ip_range):
    # Create ARP request packet
    arp_request = scapy.ARP(pdst=ip_range)
    # Create broadcast packet
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    # Combine packets
    arp_request_broadcast = broadcast/arp_request
    # Send packets and receive responses
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
    
    clients_list = []
    for element in answered_list:
        client_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
        clients_list.append(client_dict)
    return clients_list

# Scan local network (adjust IP range as needed)
scan_result = scan_network("192.168.1.1/24")

# Print results
for client in scan_result:
    print(client["ip"] + "\t\t" + client["mac"])

Why this step? This script helps you discover devices on your local network, which is an important part of understanding your digital environment's security landscape.

3. Test Your Network Scanner

Save your file and run it using:

python network_scanner.py

You should see a list of IP addresses and MAC addresses of devices connected to your network. This gives you visibility into who or what is connected to your network.

4. Create a Website Status Checker

Next, let's build a simple tool to monitor website status. Create a new file called website_checker.py with this code:

import requests

def check_website_status(url):
    try:
        response = requests.get(url, timeout=5)
        if response.status_code == 200:
            print(f"{url} is up and running")
        else:
            print(f"{url} returned status code: {response.status_code}")
    except requests.exceptions.RequestException as e:
        print(f"{url} is down or unreachable: {e}")

# Check a few websites
websites = [
    "https://www.google.com",
    "https://www.github.com",
    "https://www.openai.com"
]

for site in websites:
    check_website_status(site)

Why this step? Monitoring website status helps you detect when important services might be down, which could indicate security issues or service problems.

5. Combine Both Tools into One Script

Now let's combine both tools into a single security monitoring script. Create security_monitor.py:

import scapy.all as scapy
import requests

def scan_network(ip_range):
    arp_request = scapy.ARP(pdst=ip_range)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
    
    clients_list = []
    for element in answered_list:
        client_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
        clients_list.append(client_dict)
    return clients_list

def check_website_status(url):
    try:
        response = requests.get(url, timeout=5)
        return response.status_code == 200
    except:
        return False

# Main monitoring function
print("Starting security monitoring...")

# Scan local network
print("\nScanning local network...")
scan_result = scan_network("192.168.1.1/24")
for client in scan_result:
    print(f"Device found: {client['ip']} - {client['mac']}")

# Check website status
print("\nChecking website status...")
websites = ["https://www.openai.com", "https://www.github.com", "https://www.google.com"]
for site in websites:
    if check_website_status(site):
        print(f"✓ {site} is accessible")
    else:
        print(f"✗ {site} is not accessible")

print("\nSecurity monitoring complete.")

Why this step? Combining these tools gives you a more comprehensive view of your digital security environment.

6. Run Your Security Monitor

Execute your combined script:

python security_monitor.py

This will scan your network and check website accessibility, giving you a basic security overview.

Summary

In this tutorial, you've learned how to build basic network monitoring tools using Python. While the recent news about Sam Altman's incident focuses on physical security, understanding digital security is equally important. These simple scripts help you monitor your network for unknown devices and check the status of important websites. As you progress, you can expand these tools to include more sophisticated monitoring features, alerts, and logging capabilities.

Remember, this is just the beginning of cybersecurity awareness. Always stay informed about security threats and keep your software updated.

Source: TNW Neural

Related Articles