diff options
| author | Alkalus <draknyte1@hotmail.com> | 2020-04-13 23:50:26 +0000 |
|---|---|---|
| committer | Alkalus <draknyte1@hotmail.com> | 2020-04-13 23:50:26 +0000 |
| commit | e724a728061ec4a78cff73a4a2dd46eea4af4521 (patch) | |
| tree | fee3354917be32870ec349b605990a091ace9e62 /src/Java/gtPlusPlus/core/util/sys | |
| parent | 24b1356471191a10fde6e4f1baf58ae74e87cfba (diff) | |
| parent | 87ab3c0ab5f1b682295e2a010cc88cf4ae7db51c (diff) | |
| download | GT5-Unofficial-e724a728061ec4a78cff73a4a2dd46eea4af4521.tar.gz GT5-Unofficial-e724a728061ec4a78cff73a4a2dd46eea4af4521.tar.bz2 GT5-Unofficial-e724a728061ec4a78cff73a4a2dd46eea4af4521.zip | |
Merged in MillingRecipes (pull request #7)
Milling Recipes & many other misc fixes
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/sys')
| -rw-r--r-- | src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java | 94 |
1 files changed, 19 insertions, 75 deletions
diff --git a/src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java b/src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java index b883391a86..1403713b3d 100644 --- a/src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java +++ b/src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java @@ -41,10 +41,10 @@ public class NetworkUtils { public static boolean checkNetworkIsAvailableWithValidInterface(){ try { if (hasValidNetworkInterface()){ - if (checkAddressWithTimeout("http://www.google.com", 10) || - checkAddressWithTimeout("http://www.baidu.com", 10) || - checkAddressWithTimeout("https://github.com/draknyte1/GTplusplus", 10) || - checkAddressWithTimeout("www.yahoo.com", 10)/* || + if (checkAddressWithTimeout("http://www.google.com", 100) || + checkAddressWithTimeout("http://www.baidu.com", 100) || + checkAddressWithTimeout("http://www.github.com/alkcorp/GTplusplus", 100) || + checkAddressWithTimeout("http://www.yahoo.com", 100)/* || netIsAvailableGoogle() || netIsAvailableBaidu() || netIsAvailableGithub() || @@ -63,82 +63,26 @@ public class NetworkUtils { return false; } - private static boolean netIsAvailableGoogle() { - try { - final URL url = new URL("http://www.google.com"); - final URLConnection conn = url.openConnection(); - conn.connect(); - return true; - } catch (final MalformedURLException e) { - throw new RuntimeException(e); - } catch (final IOException e) { - return false; - } - } - - private static boolean netIsAvailableBaidu() { - try { - final URL url = new URL("http://www.baidu.com"); - final URLConnection conn = url.openConnection(); - conn.connect(); - return true; - } catch (final MalformedURLException e) { - throw new RuntimeException(e); - } catch (final IOException e) { - return false; - } - } + private static boolean checkAddressWithTimeout(String URL, int timeout) { - private static boolean netIsAvailableGithub() { try { - final URL url = new URL("https://github.com/draknyte1/GTplusplus"); - final URLConnection conn = url.openConnection(); - conn.connect(); + InetAddress.getByName(URL).isReachable(timeout); //Replace with your name return true; - } catch (final MalformedURLException e) { - throw new RuntimeException(e); - } catch (final IOException e) { - return false; - } - } - - private static boolean netIsAvailableOther() { - try { - final int timeout = 200; - final InetAddress[] addresses = InetAddress.getAllByName("www.yahoo.com"); - for (final InetAddress address : addresses) { - if (address.isReachable(timeout)) { - return true; - } - return false; - } - } catch (final Exception e) { - return false; - } - return false; - } - - private static boolean checkAddressWithTimeout(String URL, int timeout) { - - try { - InetAddress.getByName(URL).isReachable(timeout); //Replace with your name - return true; - } catch (Exception e) { - return false; - } - - /*try { - final InetAddress[] addresses = InetAddress.getAllByName(URL); - for (final InetAddress address : addresses) { - if (address.isReachable(timeout)) { - return true; + } catch (Exception e) { + boolean result = false; + try { + URL urlObj = new URL(URL); + HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); + con.setRequestMethod("GET"); + con.setConnectTimeout(timeout); + con.connect(); + int code = con.getResponseCode(); + if (code == 200) { + result = true; } - return false; - } - } catch (final Exception e) { - return false; + } catch (Exception e2) {} + return result; } - return false;*/ } private static boolean hasValidNetworkInterface() throws SocketException{ |
