From 30923d95eb57db0463eb9e827d3b6b770816e7e7 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Thu, 20 Feb 2020 05:19:42 +0300 Subject: [PATCH] Fix bug #45 --- pom.xml | 2 +- .../COM/NET/NETCommunications.java | 60 ++++++++++++++----- src/main/java/nsusbloader/NSLMain.java | 2 +- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 5f641b4..27f9865 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ NS-USBloader ns-usbloader - 2.0-SNAPSHOT + 2.1-SNAPSHOT https://github.com/developersu/ns-usbloader/ diff --git a/src/main/java/nsusbloader/COM/NET/NETCommunications.java b/src/main/java/nsusbloader/COM/NET/NETCommunications.java index f91cd6f..5d353b9 100644 --- a/src/main/java/nsusbloader/COM/NET/NETCommunications.java +++ b/src/main/java/nsusbloader/COM/NET/NETCommunications.java @@ -124,20 +124,35 @@ public class NETCommunications extends Task { // todo: thows IOException? catch (SocketException | UnknownHostException e2) { logPrinter.print("NET: Can't get your computer IP using Renmin Ribao server. Returned:\n\t"+e2.getMessage(), EMsgType.FAIL); logPrinter.print("Try using 'Expert mode' and set IP manually.", EMsgType.INFO); - try { - Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); - while (enumeration.hasMoreElements()) { - NetworkInterface n = (NetworkInterface) enumeration.nextElement(); - Enumeration enumeration1 = n.getInetAddresses(); - while (enumeration1.hasMoreElements()) { - InetAddress i = (InetAddress) enumeration1.nextElement(); - logPrinter.print("Check for: " + i.getHostAddress(), EMsgType.INFO); - } - } - } - catch (SocketException socketException) { // Good block. - logPrinter.print("Can't determine possible variants. Returned:\n\t"+socketException.getMessage(), EMsgType.FAIL); - } + this.showAvalIpExamples(); + isValid = false; + close(EFileStatus.FAILED); + return; + } + } + } + // Say hello to MacOS Catalina + // Also this part could be used instead of what we have above. One day it has to be tested on all platforms and fixed (replace code above). + if (hostIP.equals("0.0.0.0")) { + Socket scoketK; + try { + scoketK = new Socket(); + scoketK.connect(new InetSocketAddress("google.com", 80)); + hostIP = scoketK.getLocalAddress().getHostAddress(); + scoketK.close(); + } catch (Exception scoketKex) { + scoketKex.printStackTrace(); + logPrinter.print("NET: Can't get your computer IP using Google server (InetSocketAddress). Returned:\n\t"+scoketKex.getMessage(), EMsgType.INFO); + try { + scoketK = new Socket(); + scoketK.connect(new InetSocketAddress("people.com.cn", 80)); + hostIP = scoketK.getLocalAddress().getHostAddress(); + scoketK.close(); + } catch (Exception scoketKexx) { + scoketKex.printStackTrace(); + logPrinter.print("NET: Can't get your computer IP using Renmin Ribao server (InetSocketAddress). Returned:\n\t"+scoketKexx.getMessage(), EMsgType.FAIL); + logPrinter.print("Try using 'Expert mode' and set IP manually.", EMsgType.INFO); + this.showAvalIpExamples(); isValid = false; close(EFileStatus.FAILED); return; @@ -212,6 +227,23 @@ public class NETCommunications extends Task { // todo: thows IOException? } isValid = true; } + /** + * Show possible variants to log area + * */ + private void showAvalIpExamples(){ + try { + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + while (enumeration.hasMoreElements()) { + NetworkInterface n = enumeration.nextElement(); + Enumeration enumeration1 = n.getInetAddresses(); + while (enumeration1.hasMoreElements()) + logPrinter.print("Check for: " + enumeration1.nextElement().getHostAddress(), EMsgType.INFO); + } + } + catch (SocketException socketException) { // Good block. + logPrinter.print("Can't determine possible variants. Returned:\n\t"+socketException.getMessage(), EMsgType.FAIL); + } + } /** * Override cancel block to close connection by ourselves * */ diff --git a/src/main/java/nsusbloader/NSLMain.java b/src/main/java/nsusbloader/NSLMain.java index 7123189..1912983 100644 --- a/src/main/java/nsusbloader/NSLMain.java +++ b/src/main/java/nsusbloader/NSLMain.java @@ -13,7 +13,7 @@ import java.util.ResourceBundle; public class NSLMain extends Application { - public static final String appVersion = "v2.0"; + public static final String appVersion = "v2.1"; @Override public void start(Stage primaryStage) throws Exception{