use dns to lookup the servers

This commit is contained in:
Lee 2024-04-29 01:14:41 +01:00
parent e0ddf6c4bf
commit 4dbea283ab
3 changed files with 33 additions and 4 deletions

@ -2,8 +2,8 @@ name: Fetch new Pia Servers
on:
schedule:
- cron: "@hourly"
#- cron: "*/5 * * * *"
# - cron: "@hourly"
- cron: "*/30 * * * *"
push:
branches: ["master"]
paths-ignore:

17
pom.xml

@ -68,6 +68,15 @@
</plugins>
</build>
<!-- Repos -->
<repositories>
<!-- Jitpack - Used for dnsjava -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- Libraries -->
<dependency>
@ -83,6 +92,14 @@
<scope>compile</scope>
</dependency>
<!-- DNS -->
<dependency>
<groupId>com.github.dnsjava</groupId>
<artifactId>dnsjava</artifactId>
<version>v3.5.2</version>
<scope>compile</scope>
</dependency>
<!-- Archive Utilities -->
<dependency>
<groupId>org.codehaus.plexus</groupId>

@ -6,6 +6,8 @@ import cc.fascinated.piaservers.model.PiaServerToken;
import com.google.gson.reflect.TypeToken;
import lombok.SneakyThrows;
import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
import org.xbill.DNS.*;
import org.xbill.DNS.Record;
import java.io.File;
import java.net.InetAddress;
@ -95,6 +97,9 @@ public class PiaManager {
System.exit(1);
}
// Set the DNS resolver to Cloudflare
Lookup.setDefaultResolver(new SimpleResolver("1.1.1.1"));
// Search for the server domains
List<PiaServerToken> domains = new ArrayList<>();
for (File file : files) {
@ -109,10 +114,17 @@ public class PiaManager {
for (String line : lines) {
if (line.startsWith("remote ")) {
String[] parts = line.split(" ");
String domain = parts[1];
String hostname = parts[1];
String region = file.getName().split("\\.")[0];
domains.add(new PiaServerToken(domain, region));
Record[] records = new Lookup(hostname, Type.A).run();
if (records == null) {
continue;
}
for (Record record : records) {
ARecord aRecord = (ARecord) record;
domains.add(new PiaServerToken(aRecord.getAddress().getHostAddress(), region));
}
break;
}
}