Solved How do I get a players PC Ip Adress?

Discussion in 'Plugin Development' started by pcgamers123, Jun 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    pcgamers123

    Is it possible to get a players PC Ip Adress? And if it is, how do I make it? (in Code)
     
  2. Offline

    TorkatoR

    Hi pcgamers123

    Here is the code for getting an IP address of a player :

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    3. if (!(sender instanceof Player)) {
    4. Bukkit.getLogger().info("Hey poday.");
    5. }
    6.  
    7. Player p = (Player) sender;
    8. if (label.equalsIgnoreCase("ip")) {
    9. p.sendMessage("Your IP address is : " + p.getAddress());
    10. return (true);
    11. }
    12. return (false);
    13. }

    I made it in a /ip command to let the player getting his own IP address. :)
    The method used here is getAddress() which takes a player. player.getAdress();
    The best use we can do here is to get an IP address of an UUID, not a player, but didn't test it yet.

    Hope it'll help you !
     
  3. Offline

    pcgamers123

    Thank you! That'll help me out!
    Thx for the quick reply!

    Hi again!
    Is there a way to store their IP Adress in a config file?
    Tried it, gave me a messdup text..
    Thx!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  4. Offline

    AoH_Ruthless

    pcgamers123
    getConfig().set(p.getName(), p.getAddress());
    saveConfig();
     
  5. Offline

    pcgamers123

    Thats exactly what I wrote in my code, but it gave me this wierd message, dont remember it atm.
    Like: "! Javaadress.InteSocketAdress !" Or Something like that.
     
  6. Offline

    AoH_Ruthless

  7. Offline

    pcgamers123

    It said something like " ! InetSocketAdress !" And some more. Sorry, all I remember
     
  8. Offline

    joeygallegos

    pcgamers123 try doing
    Code:java
    1. p.getAddress().toString()
     
  9. Offline

    Plo124

    joeygallegos pcgamers123
    Even better
    Code:java
    1. p.getAddress().getHostString();

    Removed the / at the start of the ip (e.g. /127.0.0.1)
     
  10. Offline

    pcgamers123

    Thank you!
     
Thread Status:
Not open for further replies.

Share This Page