@echo off
REM Change to the script's directory (so it works from anywhere)
cd /d %~dp0

REM Check for Python
python --version >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
    echo Python not found. Downloading and installing Python...
    powershell -Command "Invoke-WebRequest -Uri https://www.python.org/ftp/python/3.11.5/python-3.11.5-amd64.exe -OutFile python-installer.exe"
    start /wait python-installer.exe /quiet InstallAllUsers=1 PrependPath=1
    del python-installer.exe
)

REM Check for Nmap
where nmap >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
    echo Nmap not found. Downloading and installing Nmap...
    powershell -Command "Invoke-WebRequest -Uri https://nmap.org/dist/nmap-7.94-setup.exe -OutFile nmap-installer.exe"
    start /wait nmap-installer.exe /S
    del nmap-installer.exe
    echo Nmap installation completed.
)

REM Install Python dependencies
pip install -r requirements.txt

REM Run the app and open browser
start python app.py
timeout /t 3 /nobreak >nul
start http://127.0.0.1:5000
echo.
echo Network Vulnerability Scanner is starting...
echo Browser should open automatically in a few seconds.
echo If it doesn't, manually go to: http://127.0.0.1:5000
echo.
echo Press any key to stop the server...
pause >nul 