Check if another IP is online?

Discussion in 'Plugin Development' started by thebigdolphin1, Nov 26, 2012.

Thread Status:
Not open for further replies.
  1. I want a basic bit of code to check if a server IP is online or offline, in a boolean.
    I cant find a website that says true/false to grab HTML from, or any quicker ways.

  2. Offline


    Something like:

    public boolean checkIPisOnline(Player player, String ip){
     for(Player p : Bukkit.getServer().getOnlinePlayers()){
      if(p.getAddress().getIp() == player.getAddress().getIp()){
      return false;
    I know this code won't work, but what to do is iterate over online players, and onJoin check if a player online already has the IP
  3. Offline


    I don't think he wants to check if there's a player with a certain IP online, but I think he wants to check if a server is online / offline.
  4. ^ Correct


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 30, 2016
  5. Offline


    which programming language are you requesting this in?
  6. Offline


    Assume it's java, most plugins are. Although it is a reasonable request.
  7. Offline


    Here is an incredibly simple way to check if the server is online. I'm fairly positive that it will return a false-positive if the server is "frozen" but still on.

    public static boolean isRemoteOnline(String host, int port){
    new Socket(host,port).close();
    return true;
    }catch(Exception e){ return false;}
  8. skore87 this method works great. Only one problem: It takes like 10 seconds to obtain the server.
    Is this the fastest way?
  9. Offline


    10 seconds?? What kind of backwards ISP are you or the server running on? It should be relatively quick.
  10. Hmm ok.
    It was probably slow cos I test plugins on my 1Mb/s internet! :p
  11. Offline


    This. As long as you aren't calling Bukkit methods or accessing variables in other threads that aren't thread safe, do it in another thread. And since you aren't, I think it should be fine.
Thread Status:
Not open for further replies.

Share This Page