Skip to content

Commit

Permalink
fixing buggy gpt code
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberRoute committed Sep 23, 2024
1 parent 9ecebff commit 0e12821
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
31 changes: 23 additions & 8 deletions core/networking.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
"""
This module provides functions for enabling/disabling IP forwarding
and retrieving the IP address of the current machine.
"""

import subprocess
import socket
import core.platform as platform
from core import platform


def enable_ip_forwarding():
"""
Enables IP forwarding on the current machine.
IP forwarding is enabled based on the operating system type
(macOS, Linux, or Windows).
"""
os_platform = platform.get_os()

cmd = None
if os_platform == 'mac':
cmd = ['/usr/sbin/sysctl', '-w', 'net.inet.ip.forwarding=1']
elif os_platform == 'linux':
cmd = ['sysctl', '-w', 'net.ipv4.ip_forward=1']
elif os_platform == 'windows':
cmd = ['powershell', 'Set-NetIPInterface', '-Forwarding', 'Enabled']

else:
raise ValueError(f"Unsupported OS platform: {os_platform}")
assert subprocess.call(cmd) == 0


def disable_ip_forwarding():
"""
Disables IP forwarding on the current machine.
IP forwarding is disabled based on the operating system type
(macOS, Linux, or Windows).
"""
os_platform = platform.get_os()

cmd = None
if os_platform == 'mac':
cmd = ['/usr/sbin/sysctl', '-w', 'net.inet.ip.forwarding=0']
elif os_platform == 'linux':
cmd = ['sysctl', '-w', 'net.ipv4.ip_forward=0']
elif os_platform == 'windows':
cmd = ['powershell', 'Set-NetIPInterface', '-Forwarding', 'Disabled']
else:
raise ValueError(f"Unsupported OS platform: {os_platform}")

assert subprocess.call(cmd) == 0

def get_ip_address():
"""Get the IP address of the current machine."""
try:
# Create a socket object
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
# Connect to a remote server (doesn't have to be reachable)
s.connect(("8.8.8.8", 80))
# Get the IP address of the current machine
ip_address = s.getsockname()[0]
return ip_address
except Exception as e:
except OSError as e:
print(f"Error while getting IP address: {e}")
return None
10 changes: 7 additions & 3 deletions core/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ def _load_from_file(cls, filename):
"""
with open(filename, 'r', encoding='utf-8') as file:
csvreader = csv.reader(file)
next(csvreader) # Skip header
mac_vendor_data = {}
for row in csvreader:
oui = row[1].replace("-", "").upper()[:6]
vendor = row[2]
# Ensure the row has at least 2 elements (OUI and vendor name)
if len(row) < 2:
continue

oui = row[0].replace("-", "").upper()[:6] # OUI is in the first column (index 0)
vendor = row[1] # Vendor name is in the second column (index 1)
print(f"Processing OUI: {oui}, Vendor: {vendor}")
mac_vendor_data[oui] = vendor
return mac_vendor_data

Expand Down

0 comments on commit 0e12821

Please sign in to comment.