44import java .io .IOException ;
55import java .lang .management .ManagementFactory ;
66import java .net .InetAddress ;
7+ import java .net .InetSocketAddress ;
8+ import java .net .Socket ;
79import java .net .UnknownHostException ;
810import java .sql .Timestamp ;
911import java .time .Instant ;
@@ -51,12 +53,30 @@ public static void sendUptime() throws UnknownHostException, IOException, Interr
5153 long free = diskPartition .getFreeSpace ();
5254 long total = diskPartition .getTotalSpace ();
5355
56+ boolean alternativePing = true ;
57+
58+ String adress1 = "www.google.fr" ;
59+ boolean isPinged = false ;
60+ String adress2 = "www.discord.com" ;
61+ boolean isPinged2 = false ;
62+
63+ int port = 80 ;
64+ int timeout = 2000 ;
65+
5466 long currentTime = System .currentTimeMillis ();
55- boolean isPinged = InetAddress .getByName ("www.google.fr" ).isReachable (2000 );
67+ if (alternativePing ) {
68+ isPinged = connectSocket (adress1 , port , timeout );
69+ } else {
70+ isPinged = InetAddress .getByName (adress1 ).isReachable (timeout );
71+ }
5672 currentTime = System .currentTimeMillis () - currentTime ;
5773
5874 long currentTime2 = System .currentTimeMillis ();
59- boolean isPinged2 = InetAddress .getByName ("www.discord.com" ).isReachable (2000 );
75+ if (alternativePing ) {
76+ isPinged2 = InetAddress .getByName (adress2 ).isReachable (timeout );
77+ } else {
78+ isPinged2 = connectSocket (adress2 , port , timeout );
79+ }
6080 currentTime2 = System .currentTimeMillis () - currentTime2 ;
6181
6282 String message = "" ;
@@ -74,19 +94,32 @@ public static void sendUptime() throws UnknownHostException, IOException, Interr
7494 + Math .round (total / 1024 / 1024 / 1024 ) + " Go" ;
7595
7696 if (isPinged ) {
77- message += "\n \n **__Ping__** google.fr : " + currentTime + " Ms" ;
97+ message += "\n \n **__Ping__** " + adress1 + " : " + currentTime + " Ms" ;
7898 } else {
7999 message += "\n \n **__Ping__** : __Erreur__" ;
80100 }
81101
82102 if (isPinged2 ) {
83- message += "\n **__Ping__** discord.com : " + currentTime2 + " Ms" ;
103+ message += "\n **__Ping__** " + adress2 + " : " + currentTime2 + " Ms" ;
84104 } else {
85105 message += "\n **__Ping__** : __Erreur__" ;
86106 }
87107
88108 sendDiscordUptime (message );
89109 }
110+
111+ public static boolean connectSocket (String address , int port , int timeout ) throws IOException {
112+ Socket socket = new Socket ();
113+ try {
114+ socket .connect (new InetSocketAddress (address , port ), timeout );
115+ return true ;
116+ } catch (IOException exception ) {
117+ exception .printStackTrace ();
118+ return false ;
119+ } finally {
120+ socket .close ();
121+ }
122+ }
90123
91124 public static void sendDiscordUptime (String text ) throws InterruptedException , ExecutionException {
92125 EmbedBuilder embedBuilder = new EmbedBuilder ();
0 commit comments