This commit is contained in:
parent
0240946fc8
commit
94adbbd0fd
@ -2,7 +2,7 @@ name: Sync PIA Servers
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "*/7 * * * *"
|
- cron: "*/30 * * * *"
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches: ["master"]
|
||||||
paths: [".gitea/workflows/sync-servers.yml", "src/**", "pom.xml"]
|
paths: [".gitea/workflows/sync-servers.yml", "src/**", "pom.xml"]
|
||||||
|
@ -8,16 +8,13 @@ import lombok.NonNull;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import me.braydon.pia.readme.ReadMeManager;
|
import me.braydon.pia.readme.ReadMeManager;
|
||||||
import net.lingala.zip4j.ZipFile;
|
import net.lingala.zip4j.ZipFile;
|
||||||
import org.xbill.DNS.*;
|
|
||||||
import org.xbill.DNS.Record;
|
import org.xbill.DNS.Record;
|
||||||
|
import org.xbill.DNS.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,16 +26,30 @@ public final class PIAServerList {
|
|||||||
.create();
|
.create();
|
||||||
private static final String OPENVPN_FILES_ENDPOINT = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
|
private static final String OPENVPN_FILES_ENDPOINT = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
|
||||||
private static final File SERVERS_FILE = new File("servers.json");
|
private static final File SERVERS_FILE = new File("servers.json");
|
||||||
|
private static final int TOTAL_RUNS = 2;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void main(@NonNull String[] args) {
|
public static void main(@NonNull String[] args) {
|
||||||
Lookup.setDefaultResolver(new SimpleResolver("1.1.1.1")); // Use CF DNS
|
Map<String, String> regionAddresses = getRegionAddresses(); // Get region address from PIA
|
||||||
Set<PIAServer> servers = getNewServers(); // Get the new servers from PIA
|
Set<PIAServer> servers = new HashSet<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < TOTAL_RUNS; i++) {
|
||||||
|
int before = servers.size();
|
||||||
|
servers.addAll(getNewServers(regionAddresses)); // Add new servers from PIA
|
||||||
|
System.out.println("Added " + (servers.size() - before) + " new server(s) from PIA");
|
||||||
|
|
||||||
|
// Sleep for 3 mins
|
||||||
|
if (i < TOTAL_RUNS - 1) {
|
||||||
|
System.out.println("Sleeping, waiting for another run...");
|
||||||
|
Thread.sleep(TimeUnit.MINUTES.toMillis(3L));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete servers that haven't been seen in more than a week
|
||||||
int before = servers.size();
|
int before = servers.size();
|
||||||
servers.addAll(loadServersFromFile()); // Load servers from the file
|
servers.addAll(loadServersFromFile()); // Load servers from the file
|
||||||
System.out.println("Loaded " + (servers.size() - before) + " server(s) from the servers file");
|
System.out.println("Loaded " + (servers.size() - before) + " server(s) from the servers file");
|
||||||
|
|
||||||
// Delete servers that haven't been seen in more than a week
|
|
||||||
before = servers.size();
|
before = servers.size();
|
||||||
servers.removeIf(server -> (System.currentTimeMillis() - server.getLastSeen()) >= TimeUnit.DAYS.toMillis(7L));
|
servers.removeIf(server -> (System.currentTimeMillis() - server.getLastSeen()) >= TimeUnit.DAYS.toMillis(7L));
|
||||||
System.out.println("Removed " + (before - servers.size()) + " server(s) that haven't been seen in more than a week");
|
System.out.println("Removed " + (before - servers.size()) + " server(s) that haven't been seen in more than a week");
|
||||||
@ -58,11 +69,39 @@ public final class PIAServerList {
|
|||||||
* Get the new servers from the
|
* Get the new servers from the
|
||||||
* OpenVPN files provided by PIA.
|
* OpenVPN files provided by PIA.
|
||||||
*
|
*
|
||||||
|
* @param regionAddresses the region addresses
|
||||||
* @return the new servers
|
* @return the new servers
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows @NonNull
|
||||||
private static Set<PIAServer> getNewServers() {
|
private static Set<PIAServer> getNewServers(@NonNull Map<String, String> regionAddresses) {
|
||||||
Set<PIAServer> servers = new HashSet<>(); // The new servers to return
|
Set<PIAServer> servers = new HashSet<>(); // The new servers to return
|
||||||
|
Lookup.setDefaultResolver(new SimpleResolver("1.1.1.1")); // Use CF DNS
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : regionAddresses.entrySet()) {
|
||||||
|
String region = entry.getKey();
|
||||||
|
String address = entry.getValue();
|
||||||
|
|
||||||
|
Record[] records = new Lookup(address, Type.A).run(); // Resolve A records
|
||||||
|
if (records == null) { // No A records resolved
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
System.out.println("Resolved " + records.length + " A Records for region " + region);
|
||||||
|
for (Record record : records) {
|
||||||
|
servers.add(new PIAServer(((ARecord) record).getAddress().getHostAddress(), region, System.currentTimeMillis()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the region addresses from
|
||||||
|
* the OpenVPN files provided by PIA.
|
||||||
|
*
|
||||||
|
* @return the mapped region addresses
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
private static Map<String, String> getRegionAddresses() {
|
||||||
|
Map<String, String> regionAddresses = new HashMap<>();
|
||||||
File serversZip = new File("servers.zip"); // The zip file containing the servers
|
File serversZip = new File("servers.zip"); // The zip file containing the servers
|
||||||
|
|
||||||
// Download the OpenVPN servers zip from PIA
|
// Download the OpenVPN servers zip from PIA
|
||||||
@ -103,14 +142,8 @@ public final class PIAServerList {
|
|||||||
if (!line.startsWith("remote ")) {
|
if (!line.startsWith("remote ")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Record[] records = new Lookup(line.split(" ")[1], Type.A).run(); // Resolve A records
|
// Store the region -> address mapping
|
||||||
if (records == null) { // No A records resolved
|
regionAddresses.put(region, line.split(" ")[1]);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
System.out.println("Resolved " + records.length + " A Records for region " + region);
|
|
||||||
for (Record record : records) {
|
|
||||||
servers.add(new PIAServer(((ARecord) record).getAddress().getHostAddress(), region, System.currentTimeMillis()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
file.delete(); // Delete the OpenVPN file after reading it
|
file.delete(); // Delete the OpenVPN file after reading it
|
||||||
@ -118,7 +151,7 @@ public final class PIAServerList {
|
|||||||
}
|
}
|
||||||
serversDir.delete(); // Delete the servers dir after reading the OpenVPN files
|
serversDir.delete(); // Delete the servers dir after reading the OpenVPN files
|
||||||
|
|
||||||
return servers;
|
return regionAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# PIA-ServerList
|
# PIA-ServerList
|
||||||
An automatically updated list of IPs for PIA servers, this list is updated every hour, and servers in this list will be removed in they have not been seen in the last week.
|
An automatically updated list of IPs for PIA servers, this list is updated every hour, and servers in this list will be removed in they have not been seen in the last week.
|
||||||
|
|
||||||
Wanna see the IP list? [Click Here](./context.json)
|
Wanna see the IP list? [Click Here](./servers.json)
|
||||||
|
|
||||||
## Servers
|
## Servers
|
||||||
| Region | Servers |
|
| Region | Servers |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user