Thread: [User feedback required] Direkt Gateway, VPN, Win10
View Single Post
  #5  
Old 06.12.2019, 12:00
schwa226 schwa226 is offline
Junior Loader
 
Join Date: Nov 2019
Posts: 11
Default

This patch will add the option to enter a network interface name for direct gateway:
Code:
Index: src/jd/http/Request.java
===================================================================
--- src/jd/http/Request.java	(revision 41595)
+++ src/jd/http/Request.java	(working copy)
@@ -21,11 +21,16 @@
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.NetworkInterface;
+import java.net.InetAddress;
+import java.net.SocketException;
 import java.nio.charset.CharacterCodingException;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.regex.Pattern;
+import java.util.Enumeration;
+import java.util.Collections;
 
 import org.appwork.exceptions.ThrowUncheckedException;
 import org.appwork.exceptions.WTFException;
@@ -897,6 +902,29 @@
             this.proxy = proxy;
         } else {
             this.proxy = new ClonedProxy(proxy);
+            switch (this.proxy.getType()) {
+                case DIRECT:
+                Enumeration<NetworkInterface> nets = null;
+                try {
+                    nets = NetworkInterface.getNetworkInterfaces();
+                } catch (SocketException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+
+                if (nets != null) {
+                    for (NetworkInterface netint : Collections.list(nets)) {
+                        if (StringUtils.equalsIgnoreCase(netint.getDisplayName(), this.proxy.getLocal())) {
+                            Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
+                            if (inetAddresses.hasMoreElements()) {
+                                this.proxy.setLocal(inetAddresses.nextElement().getHostAddress());
+                            }
+                            break;
+                        }
+                    }
+                    break;
+                }
+            }
         }
     }
Get the interface name by ipconfig/ifconfig and enter it as "Host/IP/Address". JDBrowser will search all adapter for a matching display name and use the IP for this direct proxy. This solve the issue of a dynamic IP on interfaces.
The patch is quick and dirty as I am not a Java programer
Reply With Quote