Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31
  1. #16
    The richest man is not the one who has the most but the one who needs the least.
    MPGH Member
    Alde.'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    1,706
    Reputation
    166
    Thanks
    3,627
    My Mood
    Sleepy

    Arrow RotMG Ping Checker 2.0

    Haven't been on MPGH for a while, it's nice to see people contributing.

    As a challenge, I wanted to rewrite this program to be even faster, but it only resulted in messier code :



    I ended up reading your code and finding that it is pretty elegant. The only thing that bothered me was the weird spelling and that it wasn't sorting the results.

    Changes :

    - Fixed minor Java issues
    - Added sorting


    Here are some changes I invite you to see

    Code:
    package com.main;
    
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    
    import java.io.IOException;
    import java.net.InetAddress;
    import java.util.*;
    
    public class Ping {
    	private static ArrayList<String> regions = new ArrayList<>();
    	private static ArrayList<String> sNames = new ArrayList<>();
    
    	public static void main(String[] args) {
    		System.out.println("RotMG Ping Finder by Ruusey");
    
    		long totalTime = 0L;
    		try {
    			Document doc = null;
    			totalTime = System.currentTimeMillis();
    			doc = Jsoup.connect("https://realmofthemadgodhrd.appspo*****m/char/list").get();
    
    			if (doc.getAllElements().text().contains("Error")) {
    				System.err.println("Error : '" + doc.getElementsByTag("Error").text() + "'.");
    			}
    
    			Elements ips = doc.getElementsByTag("DNS");
    			Elements names = doc.getElementsByTag("Name");
    			names.remove(0);
    			for (int i = 0; i < ips.size(); i++) {
    				String ip = ips.get(i).text();
    				String name = names.get(i).text();
    				sNames.add(name);
    
    				InetAddress host = InetAddress.getByName(ip);
    				String hostDns = host.getHostName();
    
    				int startIdx = hostDns.indexOf(".") + 1;
    				String region = hostDns.substring(startIdx, hostDns.indexOf(".", startIdx + 1));
    				if (hostDns.contains("compute-1")) {
    					regions.add("us-west-1");
    				} else {
    					regions.add(region);
    				}
    			}
    
    			HashMap<String, Long> serverAndTime = new HashMap<>();
    
    			for (int i = 0; i < regions.size(); i++) {
    				try {
    					Jsoup.connect("https://ec2." + regions.get(i) + ".amazonaws.com/ping").get();
    					long end = getPingTime(regions.get(i));
    
    					System.out.println(getPercentage(i + 1, regions.size()) + "% completed.");
    
    					serverAndTime.put(sNames.get(i), end);
    
    				} catch (Exception localException) {
    					localException.printStackTrace();
    				}
    			}
    
    			serverAndTime = sortByValue(serverAndTime);
    
    			for (String s : serverAndTime.keySet()) {
    				System.out.println("Your ping to server " + s + " is " + serverAndTime.get(s) + "ms.");
    			}
    
    			System.out.println("Total runtime is " + (System.currentTimeMillis() - totalTime) + "ms.");
    
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static long getPingTime(String addr) {
    		long start;
    		start = System.currentTimeMillis();
    		try {
    			Jsoup.connect("https://ec2." + addr + ".amazonaws.com/ping").get();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		long end = System.currentTimeMillis() - start;
    		return end;
    	}
    
    	public static int getPercentage(double current, double max) {
    		if (max == 0) {
    			return 100;
    		}
    		return (int) (current / max * 100);
    	}
    
    	// function to sort hashmap by values
    	public static HashMap<String, Long> sortByValue(HashMap<String, Long> hm) {
    		// Create a list from elements of HashMap
    		List<Map.Entry<String, Long>> list =
    				new LinkedList<>(hm.entrySet());
    
    		// Sort the list
    		Collections.sort(list, new Comparator<>() {
    			public int compare(Map.Entry<String, Long> o1,
    			                   Map.Entry<String, Long> o2) {
    				return (o1.getValue()).compareTo(o2.getValue());
    			}
    		});
    
    		// put data from sorted list to hashmap
    		HashMap<String, Long> temp = new LinkedHashMap<>();
    		for (Map.Entry<String, Long> aa : list) {
    			temp.put(aa.getKey(), aa.getValue());
    		}
    		return temp;
    	}
    
    }
    Feel free to use


    Last edited by Alde.; 03-07-2019 at 01:32 AM.
    Alde is Alde is

  2. The Following User Says Thank You to Alde. For This Useful Post:

    ruusey (03-08-2019)

  3. #17
    ruusey's Avatar
    Join Date
    May 2012
    Gender
    male
    Location
    null;
    Posts
    327
    Reputation
    21
    Thanks
    539
    My Mood
    Cynical
    Quote Originally Posted by Alde. View Post
    Haven't been on MPGH for a while, it's nice to see people contributing.

    As a challenge, I wanted to rewrite this program to be even faster, but it only resulted in messier code :



    I ended up reading your code and finding that it is pretty elegant. The only thing that bothered me was the weird spelling and that it wasn't sorting the results.

    Changes :

    - Fixed minor Java issues
    - Added sorting


    Here are some changes I invite you to see

    Code:
    package com.main;
    
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    
    import java.io.IOException;
    import java.net.InetAddress;
    import java.util.*;
    
    public class Ping {
    	private static ArrayList<String> regions = new ArrayList<>();
    	private static ArrayList<String> sNames = new ArrayList<>();
    
    	public static void main(String[] args) {
    		System.out.println("RotMG Ping Finder by Ruusey");
    
    		long totalTime = 0L;
    		try {
    			Document doc = null;
    			totalTime = System.currentTimeMillis();
    			doc = Jsoup.connect("https://realmofthemadgodhrd.appspo*****m/char/list").get();
    
    			if (doc.getAllElements().text().contains("Error")) {
    				System.err.println("Error : '" + doc.getElementsByTag("Error").text() + "'.");
    			}
    
    			Elements ips = doc.getElementsByTag("DNS");
    			Elements names = doc.getElementsByTag("Name");
    			names.remove(0);
    			for (int i = 0; i < ips.size(); i++) {
    				String ip = ips.get(i).text();
    				String name = names.get(i).text();
    				sNames.add(name);
    
    				InetAddress host = InetAddress.getByName(ip);
    				String hostDns = host.getHostName();
    
    				int startIdx = hostDns.indexOf(".") + 1;
    				String region = hostDns.substring(startIdx, hostDns.indexOf(".", startIdx + 1));
    				if (hostDns.contains("compute-1")) {
    					regions.add("us-west-1");
    				} else {
    					regions.add(region);
    				}
    			}
    
    			HashMap<String, Long> serverAndTime = new HashMap<>();
    
    			for (int i = 0; i < regions.size(); i++) {
    				try {
    					Jsoup.connect("https://ec2." + regions.get(i) + ".amazonaws.com/ping").get();
    					long end = getPingTime(regions.get(i));
    
    					System.out.println(getPercentage(i + 1, regions.size()) + "% completed.");
    
    					serverAndTime.put(sNames.get(i), end);
    
    				} catch (Exception localException) {
    					localException.printStackTrace();
    				}
    			}
    
    			serverAndTime = sortByValue(serverAndTime);
    
    			for (String s : serverAndTime.keySet()) {
    				System.out.println("Your ping to server " + s + " is " + serverAndTime.get(s) + "ms.");
    			}
    
    			System.out.println("Total runtime is " + (System.currentTimeMillis() - totalTime) + "ms.");
    
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static long getPingTime(String addr) {
    		long start;
    		start = System.currentTimeMillis();
    		try {
    			Jsoup.connect("https://ec2." + addr + ".amazonaws.com/ping").get();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		long end = System.currentTimeMillis() - start;
    		return end;
    	}
    
    	public static int getPercentage(double current, double max) {
    		if (max == 0) {
    			return 100;
    		}
    		return (int) (current / max * 100);
    	}
    
    	// function to sort hashmap by values
    	public static HashMap<String, Long> sortByValue(HashMap<String, Long> hm) {
    		// Create a list from elements of HashMap
    		List<Map.Entry<String, Long>> list =
    				new LinkedList<>(hm.entrySet());
    
    		// Sort the list
    		Collections.sort(list, new Comparator<>() {
    			public int compare(Map.Entry<String, Long> o1,
    			                   Map.Entry<String, Long> o2) {
    				return (o1.getValue()).compareTo(o2.getValue());
    			}
    		});
    
    		// put data from sorted list to hashmap
    		HashMap<String, Long> temp = new LinkedHashMap<>();
    		for (Map.Entry<String, Long> aa : list) {
    			temp.put(aa.getKey(), aa.getValue());
    		}
    		return temp;
    	}
    
    }
    Feel free to use


    Thanks for the tips, man you need a better ISP! Those ping times are crazy. I think the next step is to run this out of a thread pool and really get things moving
    Last edited by ruusey; 03-08-2019 at 01:30 PM.
    One day... machines will rule the world.

  4. #18
    The richest man is not the one who has the most but the one who needs the least.
    MPGH Member
    Alde.'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    1,706
    Reputation
    166
    Thanks
    3,627
    My Mood
    Sleepy
    Quote Originally Posted by ruusey View Post


    Thanks for the tips, man you need a better ISP! Those ping times are crazy. I think the next step is to run this out of a thread pool and really get things moving
    Yep you're right But yeah I had a VPN set to Venezuela... :P
    Alde is Alde is

  5. #19
    ruusey's Avatar
    Join Date
    May 2012
    Gender
    male
    Location
    null;
    Posts
    327
    Reputation
    21
    Thanks
    539
    My Mood
    Cynical
    Quote Originally Posted by Alde. View Post


    Yep you're right But yeah I had a VPN set to Venezuela... :P
    Not because you were scared of being ip banned because the realm developers will never see these api calls and i would say is 99% chance you couldnt get banned for spamming their cloud computers. Guessing it was for shizz and giggs
    One day... machines will rule the world.

  6. #20
    The richest man is not the one who has the most but the one who needs the least.
    MPGH Member
    Alde.'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    1,706
    Reputation
    166
    Thanks
    3,627
    My Mood
    Sleepy
    Quote Originally Posted by ruusey View Post


    Not because you were scared of being ip banned because the realm developers will never see these api calls and i would say is 99% chance you couldnt get banned for spamming their cloud computers. Guessing it was for shizz and giggs
    You're right, they don't monitor those calls :P I just have Private Internet Access loading on startup. Shizz ang giggs indeed.
    Alde is Alde is

  7. #21
    willieeieee's Avatar
    Join Date
    Jan 2016
    Gender
    male
    Posts
    18
    Reputation
    10
    Thanks
    1
    thank you mate

  8. The Following User Says Thank You to willieeieee For This Useful Post:

    ruusey (03-25-2019)

  9. #22
    DrexIsHex's Avatar
    Join Date
    Dec 2018
    Gender
    male
    Posts
    14
    Reputation
    10
    Thanks
    0
    My Mood
    Yeehaw
    This really helped me out a lot. Thanks!!

  10. #23
    The richest man is not the one who has the most but the one who needs the least.
    MPGH Member
    Alde.'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    1,706
    Reputation
    166
    Thanks
    3,627
    My Mood
    Sleepy
    Quote Originally Posted by DrexIsHex View Post
    This really helped me out a lot. Thanks!!
    lol rip /10chars
    Alde is Alde is

  11. #24
    ruusey's Avatar
    Join Date
    May 2012
    Gender
    male
    Location
    null;
    Posts
    327
    Reputation
    21
    Thanks
    539
    My Mood
    Cynical
    Quote Originally Posted by Alde. View Post


    lol rip /10chars
    When the bots make their rounds and fill up ur inbox
    One day... machines will rule the world.

  12. #25
    The richest man is not the one who has the most but the one who needs the least.
    MPGH Member
    Alde.'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    1,706
    Reputation
    166
    Thanks
    3,627
    My Mood
    Sleepy
    Quote Originally Posted by ruusey View Post


    When the bots make their rounds and fill up ur inbox
    Yep... They come here to meet their posts requirements... Worse thing is that these aren't bots, just scammers trying to create new accounts :')
    Alde is Alde is

  13. #26
    GarrettMaster's Avatar
    Join Date
    Jan 2016
    Gender
    male
    Posts
    19
    Reputation
    10
    Thanks
    2
    My Mood
    Aggressive
    Pretty good release, but is this even like, valuable? Shouldnt you be able to get a general idea of your connection just based off of location?

  14. #27
    Smoofwah's Avatar
    Join Date
    May 2015
    Gender
    male
    Posts
    8
    Reputation
    10
    Thanks
    0
    Its a better ping checker, a general idea = normal

    Numbers = better

    there's where the value is

  15. #28
    ruusey's Avatar
    Join Date
    May 2012
    Gender
    male
    Location
    null;
    Posts
    327
    Reputation
    21
    Thanks
    539
    My Mood
    Cynical
    Quote Originally Posted by GarrettMaster View Post
    Pretty good release, but is this even like, valuable? Shouldnt you be able to get a general idea of your connection just based off of location?
    Mostly useful as the rotmg client does not provide an actual ping time measurement. Some of decas boxes are hosted on a subnet of a large ec2 instance. I am from the south east yet my best ping is USW2, would not have known this otherwise.
    One day... machines will rule the world.

  16. #29
    Maik8's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Location
    Germany
    Posts
    186
    Reputation
    61
    Thanks
    854
    My Mood
    Busy
    Thanks for the ping checker, works as intended!
    Also inspired me to do one myself!

    Quote Originally Posted by Alde. View Post
    Haven't been on MPGH for a while, it's nice to see people contributing.

    As a challenge, I wanted to rewrite this program to be even faster, but it only resulted in messier code
    I have re-done a ping checker myself too since i wanted to be even faster (and a GUI). I achieved a total time needed to ping all 23 servers of about 400ms, minimum i have seen was 247ms and maximum about 4 seconds. This is possible due to Multi-Threading.

    C#
    Code:
            public void PingAllServer()
            {
                pings = 0;
                timerClearError.Start(); //will stop the current pings and start over again after 10 secs.
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start(); //Starting to count the total ping time needed
                foreach (ServerInfo server in servers)
                {
                    Thread pingThread = new Thread(delegat => PingThreadInfo(server)); //Creating a new Thread with a ServerInfo obj (ServerInfo = an object that holds some data, IP, Name, ping)
                    pingThread.IsBackground = true;
                    pingThread.Start(); //Start that Thread
                }
                while (pings < servers.Count) //Wait for all Threads to finish
                {
                    Application.DoEvents(); //Ensures to not block the GUI Thread
                }
                stopwatch.Stop(); //Stops the total time needed to ping
                AddInfoToUI(); //Just sorts and adds the values to the GUI
                lTotalTime.Text = stopwatch.ElapsedMilliseconds + " m/s"; 
                timerClearError.Stop();
            }
    
            private void PingThreadInfo(ServerInfo server)
            {
                PingServerInfo(server); //Pings the server
                pings++; //Count up to let the waiting Thread know one more finished
                Thread.CurrentThread.Abort(); //Ensures to abort this Thread, as Threads may not close properly automaticly, even like this it can fail tho)
            }
    
            private void PingServerInfo(ServerInfo server)
            {
                try //Try and catch just to be sure
                {
                    System.Net.Sockets.TcpClient c = new System.Net.Sockets.TcpClient(); //Creating a new TCPClient socket
                    Stopwatch watch = new Stopwatch();
                    watch.Start(); //Starting the stopwatch
                    c.Connect(server.ip, pingPort); //Try to connect to the server, wich will accept the request and the client will get an answer 
                    watch.Stop(); //Stop the stopwatch
                    server.lastPing = watch.ElapsedMilliseconds; //Give the server Object the ping time
                }
                catch (Exception) //Don't need to handle the catch, the Server will just be displayed as -1ms
                {
    
                }
            }
    Last edited by Maik8; 04-17-2019 at 03:49 PM.

  17. The Following User Says Thank You to Maik8 For This Useful Post:

    Alde. (10-14-2019)

  18. #30
    Zeroxis's Avatar
    Join Date
    Feb 2014
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    1
    Thanks for sharing.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. [Release] RotMG Ping Checker ~ Find your fastest server !
    By New in forum Realm of the Mad God Hacks & Cheats
    Replies: 68
    Last Post: 05-25-2019, 05:28 AM
  2. [Outdated] LoL Ping Checker EVEN MORE REGIONS UPDATE!
    By Lxys in forum League of Legends Hacks & Cheats
    Replies: 12
    Last Post: 03-25-2016, 02:08 PM
  3. [Outdated] LoL Ping Checker [v1.1] UPDATE!
    By Lxys in forum League of Legends Hacks & Cheats
    Replies: 15
    Last Post: 03-22-2016, 02:49 PM
  4. [Outdated] LoL Ping Checker! Check your ping before playing!
    By Lxys in forum League of Legends Hacks & Cheats
    Replies: 14
    Last Post: 03-20-2016, 05:10 AM
  5. [Release] Dat Ping Tho - league of legends Ping checker!
    By Crenox in forum League of Legends Hacks & Cheats
    Replies: 31
    Last Post: 01-20-2014, 10:50 AM