Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cross-platform administrative checks #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions neighbourhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import getopt
import sys
import ctypes

logging.basicConfig(format='%(asctime)s %(levelname)-5s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.DEBUG)
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -58,8 +59,15 @@ def scan_and_print_neighbors(net, interface, timeout=5):


def main(interface_to_scan=None):
if os.geteuid() != 0:
print('You need to be root to run this script', file=sys.stderr)

try:
is_admin = os.getuid() == 0
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() == 1

if not is_admin:
#if os.geteuid() != 0:
print('You need to be root/administrator to run this script', file=sys.stderr)
sys.exit(1)

for network, netmask, _, interface, address, _ in scapy.config.conf.route.routes:
Expand Down