Skip to content

Instantly share code, notes, and snippets.

@ayoubzulfiqar
Last active November 24, 2025 14:11
Show Gist options
  • Select an option

  • Save ayoubzulfiqar/d1f33be516e516b9b886bd1a73559a28 to your computer and use it in GitHub Desktop.

Select an option

Save ayoubzulfiqar/d1f33be516e516b9b886bd1a73559a28 to your computer and use it in GitHub Desktop.
DNS Unlock All Website Using GoodbyeDPI ( Deep Pocket Inspection ) With AutoTaskScheduler.
<#
.SYNOPSIS
Enhanced GoodbyeDPI Auto-Installation and Configuration Script
.DESCRIPTION
This script automates the setup of GoodbyeDPI for automatic startup with enhanced features:
- Automatic download of GoodbyeDPI
- Multiple mode selection
- Comprehensive error handling
- Logging and monitoring
- Health checks and self-repair
.PARAMETER GoodbyeDPIPath
Installation directory for GoodbyeDPI
.PARAMETER Mode
GoodbyeDPI operation mode (1=Light, 2=Medium, 3=Heavy, 4=Experimental)
.PARAMETER DownloadUrl
URL to download GoodbyeDPI ZIP file
.PARAMETER AutoDownload
Automatically download GoodbyeDPI if not present
#>
param(
[string]$GoodbyeDPIPath = "D:\Softwares\GoodByeDPI\x86_64",
[ValidateSet(1,2,3,4)]
[int]$Mode = 1,
[string]$DownloadUrl = "https://github.com/ValdikSS/GoodbyeDPI/releases/latest/download/goodbyedpi.zip",
[switch]$AutoDownload
)
# Script Configuration
$Script:Config = @{
GoodbyeDPIExe = "goodbyedpi.exe"
LogFile = "goodbyedpi_service.log"
MaxRetries = 3
RetryDelay = 5
}
# Enhanced logging function
function Write-Log {
param([string]$Message, [string]$Type = "INFO")
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$LogEntry = "[$Timestamp] [$Type] $Message"
Write-Host $LogEntry -ForegroundColor $(if ($Type -eq "ERROR") { "Red" } elseif ($Type -eq "WARNING") { "Yellow" } else { "White" })
$LogEntry | Out-File -FilePath (Join-Path $GoodbyeDPIPath $Script:Config.LogFile) -Append -Encoding UTF8
}
# Function to test administrator privileges
function Test-AdminPrivileges {
return ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
}
# Function to download and extract GoodbyeDPI
function Install-GoodbyeDPI {
Write-Log "Checking GoodbyeDPI installation..."
$ExePath = Join-Path $GoodbyeDPIPath $Script:Config.GoodbyeDPIExe
if (Test-Path $ExePath) {
Write-Log "GoodbyeDPI found at: $ExePath"
return $true
}
if (-not $AutoDownload) {
Write-Log "GoodbyeDPI not found and AutoDownload not specified. Please download manually." "WARNING"
return $false
}
Write-Log "Downloading GoodbyeDPI from: $DownloadUrl"
try {
$ZipPath = Join-Path $env:TEMP "goodbyedpi.zip"
# Download using TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipPath -UserAgent "PowerShell"
if (-not (Test-Path $ZipPath)) {
throw "Download failed - file not found"
}
Write-Log "Extracting GoodbyeDPI to: $GoodbyeDPIPath"
Expand-Archive -Path $ZipPath -DestinationPath $GoodbyeDPIPath -Force
# Clean up
Remove-Item $ZipPath -Force -ErrorAction SilentlyContinue
if (Test-Path $ExePath) {
Write-Log "GoodbyeDPI installed successfully"
return $true
} else {
throw "Extraction completed but executable not found"
}
}
catch {
Write-Log "Failed to download/extract GoodbyeDPI: $($_.Exception.Message)" "ERROR"
return $false
}
}
# Function to create enhanced startup script
function New-StartupScript {
$StartupScript = @"
# Enhanced GoodbyeDPI AutoStart Script
# Generated: $(Get-Date)
# Mode: $Mode
param([switch]\$DebugMode)
`$GoodbyeDPIPath = "$GoodbyeDPIPath"
`$GoodbyeDPIExe = "$($Script:Config.GoodbyeDPIExe)"
`$LogPath = Join-Path `$GoodbyeDPIPath "$($Script:Config.LogFile)"
`$Mode = $Mode
# Enhanced logging function
function Write-ServiceLog {
param([string]`$Message, [string]`$Type = "INFO")
`$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
`$LogEntry = "[`$Timestamp] [`$Type] `$Message"
if (`$DebugMode) { Write-Host `$LogEntry }
`$LogEntry | Out-File -FilePath `$LogPath -Append -Encoding UTF8
}
try {
Write-ServiceLog "=== GoodbyeDPI Service Start ==="
# Verify executable exists
`$ExePath = Join-Path `$GoodbyeDPIPath `$GoodbyeDPIExe
if (-not (Test-Path `$ExePath)) {
Write-ServiceLog "ERROR: GoodbyeDPI executable not found at: `$ExePath" "ERROR"
exit 1
}
Set-Location -Path `$GoodbyeDPIPath
# Check if already running
`$ExistingProcess = Get-Process -Name "goodbyedpi" -ErrorAction SilentlyContinue
if (`$ExistingProcess) {
Write-ServiceLog "GoodbyeDPI already running (PID: `$(`$ExistingProcess.Id)), terminating for clean start"
`$ExistingProcess | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 3
}
# Start GoodbyeDPI with selected mode
`$Arguments = "-`$Mode"
Write-ServiceLog "Starting GoodbyeDPI with mode: `$Mode (Arguments: `$Arguments)"
`$Process = Start-Process -FilePath `$GoodbyeDPIExe -ArgumentList `$Arguments -WindowStyle Hidden -PassThru
# Wait and verify
Start-Sleep -Seconds 5
`$NewProcess = Get-Process -Name "goodbyedpi" -ErrorAction SilentlyContinue
if (`$NewProcess) {
Write-ServiceLog "SUCCESS: GoodbyeDPI started (PID: `$(`$Process.Id), Mode: `$Mode)"
# Monitor process health (simplified - no infinite loop that blocks task completion)
for (`$i = 0; `$i -lt 6; `$i++) {
Start-Sleep -Seconds 10
`$CurrentProcess = Get-Process -Name "goodbyedpi" -ErrorAction SilentlyContinue
if (-not `$CurrentProcess -or `$CurrentProcess.HasExited) {
Write-ServiceLog "WARNING: GoodbyeDPI process terminated, will restart on next schedule" "WARNING"
break
}
}
Write-ServiceLog "GoodbyeDPI monitoring completed - process is stable"
} else {
Write-ServiceLog "ERROR: GoodbyeDPI failed to start" "ERROR"
exit 1
}
}
catch {
Write-ServiceLog "UNHANDLED ERROR: `$(`$_.Exception.Message)" "ERROR"
exit 1
}
"@
$ScriptPath = Join-Path $GoodbyeDPIPath "start_goodbyedpi.ps1"
$StartupScript | Out-File -FilePath $ScriptPath -Encoding UTF8
# Unblock the script file to prevent execution issues
Unblock-File -Path $ScriptPath -ErrorAction SilentlyContinue
Write-Log "Enhanced startup script created: $ScriptPath"
}
# Function to create scheduled task (FIXED VERSION)
function New-ScheduledTask {
$TaskName = "GoodbyeDPI AutoStart"
# Remove existing task if present
$ExistingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
if ($ExistingTask) {
Write-Log "Removing existing scheduled task: $TaskName"
try {
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
Start-Sleep -Seconds 2
} catch {
Write-Log "Warning: Could not remove existing task: $($_.Exception.Message)" "WARNING"
}
}
# Create enhanced task action with execution policy bypass
$ScriptPath = Join-Path $GoodbyeDPIPath "start_goodbyedpi.ps1"
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$ScriptPath`""
# Startup trigger with delay to ensure network is available
$Trigger = New-ScheduledTaskTrigger -AtStartup
$Trigger.Delay = "PT1M" # 1 minute delay
# Enhanced settings
$Settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-StartWhenAvailable `
-RestartCount 3 `
-RestartInterval (New-TimeSpan -Minutes 5) `
-MultipleInstances IgnoreNew
# Use Current User instead of SYSTEM for better compatibility
$Principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType Interactive -RunLevel Highest
# Register task
try {
Register-ScheduledTask `
-TaskName $TaskName `
-Action $Action `
-Trigger $Trigger `
-Settings $Settings `
-Principal $Principal `
-Description "Automatically starts GoodbyeDPI on system startup with enhanced monitoring and auto-restart capabilities" `
-Force
Write-Log "Enhanced scheduled task created: $TaskName"
return $true
} catch {
Write-Log "Failed to create scheduled task: $($_.Exception.Message)" "ERROR"
# Fallback: Try with simplest configuration
Write-Log "Attempting fallback task creation..."
try {
Register-ScheduledTask `
-TaskName $TaskName `
-Action $Action `
-Trigger (New-ScheduledTaskTrigger -AtStartup) `
-Settings (New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries) `
-RunLevel Highest `
-Force
Write-Log "Fallback scheduled task created successfully" "INFO"
return $true
} catch {
Write-Log "Fallback task creation also failed: $($_.Exception.Message)" "ERROR"
return $false
}
}
}
# Function to create startup folder shortcut as backup
function New-StartupShortcut {
Write-Log "Creating startup folder shortcut as backup method..."
try {
$StartupFolder = [System.Environment]::GetFolderPath('Startup')
$ShortcutPath = Join-Path $StartupFolder "GoodbyeDPI.lnk"
# Create the shortcut
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutPath)
$Shortcut.TargetPath = "powershell.exe"
$Shortcut.Arguments = "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$(Join-Path $GoodbyeDPIPath "start_goodbyedpi.ps1")`""
$Shortcut.WorkingDirectory = $GoodbyeDPIPath
$Shortcut.WindowStyle = 7 # Minimized
$Shortcut.Save()
Write-Log "Startup shortcut created: $ShortcutPath"
return $true
} catch {
Write-Log "Failed to create startup shortcut: $($_.Exception.Message)" "WARNING"
return $false
}
}
# Function to test the setup
function Test-Setup {
Write-Log "Testing GoodbyeDPI setup..."
$TestsPassed = 0
$TotalTests = 3
# Test 1: Script file exists
$ScriptPath = Join-Path $GoodbyeDPIPath "start_goodbyedpi.ps1"
if (Test-Path $ScriptPath) {
Write-Log "✓ Startup script verified: $ScriptPath"
$TestsPassed++
} else {
Write-Log "✗ Startup script not found" "ERROR"
}
# Test 2: Task registration
$Task = Get-ScheduledTask -TaskName "GoodbyeDPI AutoStart" -ErrorAction SilentlyContinue
if ($Task) {
Write-Log "✓ Scheduled task verified"
$TestsPassed++
# Test task can run
try {
Start-ScheduledTask -TaskName "GoodbyeDPI AutoStart"
Start-Sleep -Seconds 3
$TaskInfo = Get-ScheduledTask -TaskName "GoodbyeDPI AutoStart" | Get-ScheduledTaskInfo
if ($TaskInfo.LastTaskResult -eq 0 -or $TaskInfo.LastTaskResult -eq 267009) {
Write-Log "✓ Scheduled task starts successfully"
} else {
Write-Log "⚠ Scheduled task may have issues (LastResult: $($TaskInfo.LastTaskResult))" "WARNING"
}
} catch {
Write-Log "⚠ Could not test task execution: $($_.Exception.Message)" "WARNING"
}
} else {
Write-Log "✗ Scheduled task not found" "ERROR"
}
# Test 3: GoodbyeDPI executable
$ExePath = Join-Path $GoodbyeDPIPath $Script:Config.GoodbyeDPIExe
if (Test-Path $ExePath) {
Write-Log "✓ GoodbyeDPI executable verified: $ExePath"
$TestsPassed++
} else {
Write-Log "✗ GoodbyeDPI executable not found" "ERROR"
}
Write-Log "Setup tests: $TestsPassed/$TotalTests passed"
return $TestsPassed -eq $TotalTests
}
# Function to start GoodbyeDPI immediately
function Start-GoodbyeDPI {
Write-Log "Starting GoodbyeDPI immediately..."
$ScriptPath = Join-Path $GoodbyeDPIPath "start_goodbyedpi.ps1"
try {
Start-Process PowerShell -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$ScriptPath`"" -Verb RunAs
Write-Log "GoodbyeDPI start command executed"
# Wait and verify
Start-Sleep -Seconds 5
$Process = Get-Process -Name "goodbyedpi" -ErrorAction SilentlyContinue
if ($Process) {
Write-Log "✓ GoodbyeDPI is now running (PID: $($Process.Id))" "INFO"
return $true
} else {
Write-Log "⚠ GoodbyeDPI process not detected - check log file" "WARNING"
return $false
}
} catch {
Write-Log "Failed to start GoodbyeDPI: $($_.Exception.Message)" "ERROR"
return $false
}
}
# Main execution
Write-Log "Starting Enhanced GoodbyeDPI Auto-Installation"
Write-Log "Installation path: $GoodbyeDPIPath"
Write-Log "Selected mode: $Mode"
# Check admin privileges
if (-not (Test-AdminPrivileges)) {
Write-Log "This script requires administrator privileges. Please run as Administrator." "ERROR"
exit 1
}
# Create directory
if (-not (Test-Path $GoodbyeDPIPath)) {
Write-Log "Creating directory: $GoodbyeDPIPath"
New-Item -ItemType Directory -Path $GoodbyeDPIPath -Force | Out-Null
}
# Install GoodbyeDPI
if (-not (Install-GoodbyeDPI)) {
Write-Log "GoodbyeDPI installation failed. Please download manually from:" "ERROR"
Write-Log "https://github.com/ValdikSS/GoodbyeDPI/releases" "ERROR"
exit 1
}
# Create enhanced startup script
New-StartupScript
# Create scheduled task
$TaskCreated = New-ScheduledTask
# Create startup shortcut as backup
$ShortcutCreated = New-StartupShortcut
# Test setup
if (Test-Setup) {
Write-Log "Enhanced GoodbyeDPI auto-start setup completed successfully!" "INFO"
Write-Log "GoodbyeDPI will automatically start with Windows in Mode $Mode" "INFO"
Write-Log "Log file: $(Join-Path $GoodbyeDPIPath $Script:Config.LogFile)" "INFO"
# Offer to start immediately
$StartNow = Read-Host "Would you like to start GoodbyeDPI now? (Y/N)"
if ($StartNow -eq 'Y' -or $StartNow -eq 'y') {
$Started = Start-GoodbyeDPI
if (-not $Started) {
Write-Log "Manual start may have failed. Check the log file for details." "WARNING"
}
}
} else {
if ($ShortcutCreated) {
Write-Log "Setup completed with warnings, but startup shortcut was created as backup." "WARNING"
Write-Log "GoodbyeDPI should start when you next log in." "INFO"
} else {
Write-Log "Setup completed with errors. Please review the messages above." "ERROR"
}
}
# Final status
Write-Log "=== Setup Summary ==="
Write-Log "Installation Path: $GoodbyeDPIPath"
Write-Log "Operation Mode: $Mode"
Write-Log "Scheduled Task: $(if ($TaskCreated) {'Created'} else {'Failed'})"
Write-Log "Startup Shortcut: $(if ($ShortcutCreated) {'Created'} else {'Failed'})"
Write-Log "Log File: $(Join-Path $GoodbyeDPIPath $Script:Config.LogFile)"
if ($TaskCreated -or $ShortcutCreated) {
Write-Log "GoodbyeDPI should now start automatically with Windows!" "INFO"
} else {
Write-Log "Automatic startup setup failed. Please run the script manually after reboot." "ERROR"
}
Write-Log "Setup completed at: $(Get-Date)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment