-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b8b6156
Showing
22 changed files
with
707 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Give process admin privileges: | ||
param([switch]$Elevated) | ||
|
||
function Test-Admin { | ||
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | ||
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | ||
} | ||
|
||
if ((Test-Admin) -eq $false) { | ||
if ($elevated) | ||
{ | ||
# tried to elevate, did not work, aborting | ||
} | ||
else { | ||
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) | ||
# If we want to keep the window open after running: | ||
# Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) | ||
} | ||
|
||
exit | ||
} | ||
|
||
'Running with full privileges' | ||
|
||
# Get WSL virtual IP: | ||
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '" | ||
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; | ||
|
||
if( $found ){ | ||
$remoteport = $matches[0]; | ||
} else{ | ||
Write-Output "The Script Exited, the ip address of WSL 2 cannot be found"; | ||
exit; | ||
} | ||
|
||
#[Ports] | ||
|
||
#All the ports you want to forward separated by coma | ||
$ports=@(80,2223,3000); | ||
|
||
|
||
#[Static ip] | ||
#You can change the addr to your ip config to listen to a specific address | ||
$addr='0.0.0.0'; | ||
$ports_a = $ports -join ","; | ||
|
||
#[Firewall] | ||
#More often than not, Windows firewall will block connections even from local network, so | ||
#we will open the ports above for PRIVATE connections only. It is STRONGLY advised against | ||
#opening ports in Public networks, specially for mobile devices that may automatically | ||
#connect to unsafe networks. If you're sure you want Public access to your server, then | ||
#change the rules below under the "-Profile" option (look up the right syntax online): | ||
|
||
#Remove existing Firewall Exception Rules, if any | ||
Invoke-Expression "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' "; | ||
|
||
#Adding Exception Rules for inbound and outbound Rules | ||
Invoke-Expression "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Profile Private -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP"; | ||
Invoke-Expression "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Profile Private -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP"; | ||
|
||
#Bridge the connection such that your | ||
for( $i = 0; $i -lt $ports.length; $i++ ){ | ||
$port = $ports[$i]; | ||
Invoke-Expression "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr"; | ||
Invoke-Expression "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport"; | ||
} | ||
|
||
exit |