How to get IP of the user when he signs in?

How to get the ip address of the client when he signs in?
I tried using this code

import java.net.*; 
import java.io.*; 
import java.util.*; 
import java.net.InetAddress; 

public class JavaProgram 
{ 
	public static void main(String args[]) throws Exception 
	{ 
		// Returns the instance of InetAddress containing 
		// local host name and address 
		InetAddress localhost = InetAddress.getLocalHost(); 
		System.out.println("System IP Address : " + 
					(localhost.getHostAddress()).trim()); 

		// Find public IP address 
		String systemipaddress = ""; 
		try
		{ 
			URL url_name = new URL("http://bot.whatismyipaddress.com"); 

			BufferedReader sc = 
			new BufferedReader(new InputStreamReader(url_name.openStream())); 

			// reads system IPAddress 
			systemipaddress = sc.readLine().trim(); 
		} 
		catch (Exception e) 
		{ 
			systemipaddress = "Cannot Execute Properly"; 
		} 
		System.out.println("Public IP Address: " + systemipaddress +"\n"); 
	} 
} 

But this gives the Server IP

Does this help?

1 Like

Well yes if you make the call from the server of course an IP service will tell you the server's address. I think the bigger question philosophically is why would you need this information in the first place? We run App Inventor just fine without it.

2 Likes

Because as we keep limits on how many projects you keep, we want our users to keep only one account there.

Second reason, we want to inform users that a new IP address just signed in your account.

That's not fine seeing other's IP. If There is 1 account limit also then we can easily manage to have more than 1 accounts, and these days some VPN are free. :roll_eyes:

That has no problem, until we not add it in our privacy policy.
Does Google not collect your IP when you sign in and show that you just signed in from a new computer? same with kodular.

If we get to know that somehow, your both accounts will be banned and both IPs too. It will be better to ban all free VPN IPs.

You can't differentiate between a free vpn and the original one
Also some phones and computers have inbuilt vpn on them
So it's impossible to do so

can you please give some example?

Redmi phones have free vpn

Ha Ha Ha, that is a option to select an app as a default vpn app.

Mostly every phone has that option.

#off-topic

Again same thing:

Turbo vpn
People will use this

#off-topic


I can select my own vpn

public static String getLocalIpAddress() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                    return inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    return null;
}

This might help you, I have tried it before.

Thanks for code, but it doesn't work, as @ewpatton said

1 Like

anyone here?