Skip to content

Commit

Permalink
Minor network update (#11)
Browse files Browse the repository at this point in the history
* updated to allow for networks that don't follow the
standard 192 or localhost setup.

* Resolved conflicts with PR

Re-adding recent changes
  • Loading branch information
sylos authored Apr 6, 2024
1 parent bea889e commit f6fe3bd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions main_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import zipfile
import os
import importlib
import ipaddress
from pathlib import Path
import inspect

Expand Down Expand Up @@ -1208,13 +1209,20 @@ def get_local_ip():
# Middleware to check request IP address
@app.before_request
def check_local_network():
remote_ip = request.remote_addr
remote_ip = request.remote_addr

netmask = '255.255.255.0'

ip_local = ipaddress.IPv4Network(local_ip + '/' + netmask, strict=False)
ip_remote = ipaddress.IPv4Network(remote_ip + '/' + netmask, strict=False)

#print(f"local IP is: {local_ip}")
#print(f"remote: {remote_ip}")
#print(f"IP1: {ip_local} == IP2: {ip_remote} {ip_local == ip_remote}")

# print(f'new connection established: {remote_ip}')
if (
remote_ip != local_ip
and not remote_ip.startswith("127.")
and not remote_ip.startswith("192.168.")
):

if ip_remote != ip_local:
return (
"Unauthorized access: you are not on the same network as the server.",
403,
Expand Down

0 comments on commit f6fe3bd

Please sign in to comment.