-
Notifications
You must be signed in to change notification settings - Fork 1
/
IpUpdate.ps1
executable file
·232 lines (198 loc) · 6.83 KB
/
IpUpdate.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
function Show-InteractiveMenu {
$services = @(
"Select all",
"Cloudflare",
"CS2",
"Websupport SK",
"Gcore",
"Hunt: Showdown EU",
"Fastly",
"Github Ucontent"
)
$selected = @($false, $false, $false, $false, $false, $false, $false, $false)
$currentIndex = 0
function Display-Menu {
Clear-Host
Write-Host "Use arrow keys to navigate and space to select/deselect. Press Enter to confirm."
for ($i = 0; $i -lt $services.Length; $i++) {
$selectionMarker = if ($selected[$i]) { "[X]" } else { "[ ]" }
if ($i -eq $currentIndex) {
Write-Host ">> $selectionMarker $($services[$i])"
} else {
Write-Host " $selectionMarker $($services[$i])"
}
}
}
while ($true) {
Display-Menu
$key = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
switch ($key.VirtualKeyCode) {
38 { # Up arrow key
$currentIndex = if ($currentIndex -gt 0) { $currentIndex - 1 } else { $services.Length - 1 }
}
40 { # Down arrow key
$currentIndex = if ($currentIndex -lt $services.Length - 1) { $currentIndex + 1 } else { 0 }
}
32 { # Space key
if ($currentIndex -eq 0) {
# Ha a "Select all" opció van kiválasztva, állítsuk be az összes többi opciót is
$allSelected = -not $selected[0]
for ($j = 0; $j -lt $selected.Length; $j++) {
$selected[$j] = $allSelected
}
} else {
# Csak az adott opció állapota változik
$selected[$currentIndex] = -not $selected[$currentIndex]
}
}
13 { # Enter key
return $selected
}
}
}
}
function Get-IPListForService {
param (
[string]$service
)
$url = ""
switch ($service) {
"Cloudflare" {
$url = "https://fxtelekom.org/ips/cloudflare.txt"
}
"CS2" {
$url = "https://fxtelekom.org/ips/valve-cs2.txt"
}
"Websupport SK" {
$url = "https://fxtelekom.org/ips/websupportsk.txt"
}
"Gcore" {
$url = "https://fxtelekom.org/ips/gcore.txt"
}
"Hunt: Showdown EU" {
$url = "https://fxtelekom.org/ips/hunt.txt"
}
"Fastly" {
$url = "https://fxtelekom.org/ips/fastly.txt"
}
"Github Ucontent" {
$url = "https://fxtelekom.org/ips/github-ucontent.txt"
}
default {
Write-Error "Invalid service selection."
exit 1
}
}
try {
$ipList = Invoke-WebRequest -Uri $url -UseBasicParsing
$ipAddresses = $ipList.Content -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne "" }
return $ipAddresses
} catch {
Write-Error "Failed to download IP list for service $service : $_"
exit 1
}
}
function Get-DefaultIPs {
param (
[string]$url = "https://fxtelekom.org/ips/intern.txt"
)
try {
$ipListContent = Invoke-WebRequest -Uri $url -UseBasicParsing
}
catch {
Write-Error "Failed to download the IP list from the specified URL."
return
}
$trimmedIPs = $ipListContent.Content -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne "" }
$defaultIPs = $trimmedIPs -join ", "
return $defaultIPs
}
function Get-DNSIPs{
param (
[string]$url = "https://fxtelekom.org/ips/dns.txt"
)
try {
$ipListContent = Invoke-WebRequest -Uri $url -UseBasicParsing
}
catch {
Write-Error "Failed to download the IP list from the specified URL."
return
}
$trimmedIPs = $ipListContent.Content -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne "" }
$DNSIPs = $trimmedIPs -join ", "
return $DNSIPs
}
$logo = @"
________ _________ ______ _ ______ _ ______ __ __
| ____\ \ / /__ __| ____| | | ____| |/ / __ \| \/ |
| |__ \ V / | | | |__ | | | |__ | ' / | | | \ / |
| __| > < | | | __| | | | __| | <| | | | |\/| |
| | / . \ | | | |____| |____| |____| . \ |__| | | | |
|_| /_/ \_\ |_| |______|______|______|_|\_\____/|_| |_|
"@
Clear-Host
Write-Host @"
$logo
This script will enter the IP ranges for your selected services in your wireguard config file.
You can run it when we add a new list or update an existing one, and you want to use it for a newly added service or one of the old ranges is extended!
"@
$configPath = Read-Host "Enter the full path to the wg config file"
if (-Not (Test-Path $configPath)) {
Write-Error "The specified wg.conf file does not exist: $configPath"
exit 1
}
$selected = Show-InteractiveMenu
$ipAddresses = @()
$services = @(
"I want it all!",
"Cloudflare",
"CS2",
"Websupport SK",
"Gcore",
"Hunt: Showdown EU",
"Fastly",
"Github Ucontent"
)
if ($selected[0]) {
for ($i = 1; $i -lt $services.Length; $i++) {
Write-Host "Processing service: $($services[$i])"
$ipAddresses += Get-IPListForService $services[$i]
}
} else {
for ($i = 1; $i -lt $services.Length; $i++) {
if ($selected[$i]) {
Write-Host "Processing service: $($services[$i])"
$ipAddresses += Get-IPListForService $services[$i]
}
}
}
$configContent = Get-Content -Path $configPath
$defaultIPs = Get-DefaultIPs
$DNSIPs = Get-DNSIPs
$allowedIPs = $defaultIPs + ", " + ($ipAddresses -join ', ')
try {
$allowedIPsFound = $false
$DNSFound = $false
$updatedContent = $configContent | ForEach-Object {
if ($_ -match "^DNS\s*=") {
$DNSFound = $true
"DNS = $DNSIPs"
}
elseif ($_ -match "^AllowedIPs\s*=") {
$allowedIPsFound = $true
"AllowedIPs = $allowedIPs"
}
else {
$_
}
}
if (-not $allowedIPsFound) {
Write-Error "'AllowedIPs =' field not found in the configuration file."
exit 1
}
Set-Content -Path $configPath -Value $updatedContent
Write-Host "`nwg.conf updated with the following IP addresses:`nDNS: $DNSIPs`nAllowedIPs: $allowedIPs"
Write-Host "`nHave a good time with your new fast internet :)"
} catch {
Write-Error "Error processing the configuration file: $_"
}