Can I found Players IP address

Started by azizjuaneten5858 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can I found Players IP address

I want to make a mod and in the mod I want to find the person's current IP address and write something like "Your IP address is 123" 5-10 blocks away from the player. Is this possible?

Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The only way would be custom…
Wed, 06/25/2025 - 19:57

The only way would be custom code, I can give you the code that should be able to get and print the IP 

import java.net.*;
import java.util.Enumeration;

public class RealIPAddressOnly {
    public static void main(String[] args) {
        try {
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            while (interfaces.hasMoreElements()) {
                NetworkInterface iface = interfaces.nextElement();

                
                if (iface.isLoopback() || !iface.isUp())
                    continue;

                Enumeration<InetAddress> addresses = iface.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    InetAddress addr = addresses.nextElement();
                    if (addr instanceof Inet4Address) {
                        System.out.println("IP Address: " + addr.getHostAddress());
                    }
                }
            }
        } catch (SocketException e) {
            System.err.println("Error retrieving network interfaces: " + e.getMessage());
        }
    }
}