Skip to content

Commit 30923d9

Browse files
committed
Fix bug #45
1 parent 7b2e77a commit 30923d9

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<name>NS-USBloader</name>
99

1010
<artifactId>ns-usbloader</artifactId>
11-
<version>2.0-SNAPSHOT</version>
11+
<version>2.1-SNAPSHOT</version>
1212

1313
<url>https://github.com/developersu/ns-usbloader/</url>
1414
<description>

src/main/java/nsusbloader/COM/NET/NETCommunications.java

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,35 @@ public NETCommunications(List<File> filesList, String switchIP, boolean doNotSer
124124
catch (SocketException | UnknownHostException e2) {
125125
logPrinter.print("NET: Can't get your computer IP using Renmin Ribao server. Returned:\n\t"+e2.getMessage(), EMsgType.FAIL);
126126
logPrinter.print("Try using 'Expert mode' and set IP manually.", EMsgType.INFO);
127-
try {
128-
Enumeration enumeration = NetworkInterface.getNetworkInterfaces();
129-
while (enumeration.hasMoreElements()) {
130-
NetworkInterface n = (NetworkInterface) enumeration.nextElement();
131-
Enumeration enumeration1 = n.getInetAddresses();
132-
while (enumeration1.hasMoreElements()) {
133-
InetAddress i = (InetAddress) enumeration1.nextElement();
134-
logPrinter.print("Check for: " + i.getHostAddress(), EMsgType.INFO);
135-
}
136-
}
137-
}
138-
catch (SocketException socketException) { // Good block.
139-
logPrinter.print("Can't determine possible variants. Returned:\n\t"+socketException.getMessage(), EMsgType.FAIL);
140-
}
127+
this.showAvalIpExamples();
128+
isValid = false;
129+
close(EFileStatus.FAILED);
130+
return;
131+
}
132+
}
133+
}
134+
// Say hello to MacOS Catalina
135+
// 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).
136+
if (hostIP.equals("0.0.0.0")) {
137+
Socket scoketK;
138+
try {
139+
scoketK = new Socket();
140+
scoketK.connect(new InetSocketAddress("google.com", 80));
141+
hostIP = scoketK.getLocalAddress().getHostAddress();
142+
scoketK.close();
143+
} catch (Exception scoketKex) {
144+
scoketKex.printStackTrace();
145+
logPrinter.print("NET: Can't get your computer IP using Google server (InetSocketAddress). Returned:\n\t"+scoketKex.getMessage(), EMsgType.INFO);
146+
try {
147+
scoketK = new Socket();
148+
scoketK.connect(new InetSocketAddress("people.com.cn", 80));
149+
hostIP = scoketK.getLocalAddress().getHostAddress();
150+
scoketK.close();
151+
} catch (Exception scoketKexx) {
152+
scoketKex.printStackTrace();
153+
logPrinter.print("NET: Can't get your computer IP using Renmin Ribao server (InetSocketAddress). Returned:\n\t"+scoketKexx.getMessage(), EMsgType.FAIL);
154+
logPrinter.print("Try using 'Expert mode' and set IP manually.", EMsgType.INFO);
155+
this.showAvalIpExamples();
141156
isValid = false;
142157
close(EFileStatus.FAILED);
143158
return;
@@ -212,6 +227,23 @@ public NETCommunications(List<File> filesList, String switchIP, boolean doNotSer
212227
}
213228
isValid = true;
214229
}
230+
/**
231+
* Show possible variants to log area
232+
* */
233+
private void showAvalIpExamples(){
234+
try {
235+
Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
236+
while (enumeration.hasMoreElements()) {
237+
NetworkInterface n = enumeration.nextElement();
238+
Enumeration<InetAddress> enumeration1 = n.getInetAddresses();
239+
while (enumeration1.hasMoreElements())
240+
logPrinter.print("Check for: " + enumeration1.nextElement().getHostAddress(), EMsgType.INFO);
241+
}
242+
}
243+
catch (SocketException socketException) { // Good block.
244+
logPrinter.print("Can't determine possible variants. Returned:\n\t"+socketException.getMessage(), EMsgType.FAIL);
245+
}
246+
}
215247
/**
216248
* Override cancel block to close connection by ourselves
217249
* */

src/main/java/nsusbloader/NSLMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public class NSLMain extends Application {
1515

16-
public static final String appVersion = "v2.0";
16+
public static final String appVersion = "v2.1";
1717

1818
@Override
1919
public void start(Stage primaryStage) throws Exception{

0 commit comments

Comments
 (0)