Last active
December 12, 2015 08:08
-
-
Save Double0negative/4741381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataInputStream; | |
import java.io.OutputStream; | |
import java.net.Socket; | |
public class Pinger { | |
@SuppressWarnings("deprecation") | |
public static int [] ping(String ip, int port){ | |
try{ | |
Socket sk = new Socket(ip,port); | |
OutputStream out = sk.getOutputStream(); | |
out.write(0xFE); | |
out.flush(); | |
DataInputStream in = new DataInputStream(sk.getInputStream()); | |
String s = in.readLine(); | |
String s1 = ""; | |
for(int a = 0; a<s.length();a+=2){ | |
s1 = s1 + s.charAt(a); | |
} | |
String[] s2 = s1.split("§"); | |
sk.close(); | |
//return [online],[max] | |
return new int [] {Integer.parseInt(s2[s2.length-2]), Integer.parseInt(s2[s2.length-1])}; | |
} | |
catch(Exception e){ | |
//server is offline/unreachable | |
return new int []{-1,-1}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment