@@ -124,20 +124,35 @@ public NETCommunications(List<File> filesList, String switchIP, boolean doNotSer
124
124
catch (SocketException | UnknownHostException e2 ) {
125
125
logPrinter .print ("NET: Can't get your computer IP using Renmin Ribao server. Returned:\n \t " +e2 .getMessage (), EMsgType .FAIL );
126
126
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 ();
141
156
isValid = false ;
142
157
close (EFileStatus .FAILED );
143
158
return ;
@@ -212,6 +227,23 @@ public NETCommunications(List<File> filesList, String switchIP, boolean doNotSer
212
227
}
213
228
isValid = true ;
214
229
}
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
+ }
215
247
/**
216
248
* Override cancel block to close connection by ourselves
217
249
* */
0 commit comments