IP address

Hello, I try to catch the IP adress of my computer, not ! but the real one ! I think I must use java. I find this way but don't work. If anybody have an idea ?

import java.net.Inet4Address ;


  • edited July 2014
    String[] ip = loadStrings("http://" + "icanhazip.com/");

    AFAIK, you can't get the information from inside the computer, since the address is granted by your ISP.

  • hey, try

    try {
    } catch(Exception e) {}
  • ramin, that's what is mentioned in the original message...

    If I run this, I get which is the address of my computer on my local network (internal one), not the public IP used by Web servers. It can be a useful information (eg. for the Network library) but it is not what is asked.

    If the information was available from inside, there would be lot of freewares showing the information, not lot of sites doing this! Just google for what is my ip address or similar, and see... I searched for one giving the information without lot of HTML around...

  • @ramin thanks for the local adress is good. But I think I cannot use this adress to connect client-server when the computer are not in the same local network, If I understand well what say PhiLho is not possible ?

    @PhiLho I try your code but I receive message "Syntax error, insert ")" to complete Methodinvocation. When I try to use adress from "what is my ip address" I cannot manage to connect the two sketches together.

  • Answer ✓

    That's because this forum messes URLs in code...

    Let's try again:

    String[] ip = loadStrings("http://icanhazip.com/");

  • edited January 2014

    The background to it is that internet is not really divided into 'local' and 'public' - its a simplification because we are used to a single level NAT in daily life. There can be various network address translations on the way, even if for most situations there will be what you may call 'public' or 'external' ip there may be situations where it is different depending from where from you check. Imagine a string of 10 routers, each connecting to the 'wan' port of the next one. 'external' IP address of a computer connected to the last one will be different depending on the router you connect to. when a packet comes the only thing that matters is that when a response is sent back using the 'source' address it gets routed back to the source (its address may get changed few times on the way - but it doesn't matter as long as it comes home).

    Back to real-life solutions - one granted by PhiLho is good, alternatively you could put up your own PHP script that checks the IP of the client that connected and sends it back. If the server is far enough from you, there are good chances other people will be able to connect using this address (if there are no firewalls in between).

  • Thanks for the answer and sorry for my late, but the forum don't send me notification. @zumbaree If I understand I must find the adress of my router before every thing, and next I found the local adress to find to the adress of my comuter.

    @philho work perfectly now !

  • _vk_vk
    edited July 2014

    Don't know if would help, but there are sites, like http://www.noip.com and others that keep track of your changing IP for you (free). So you can always connect to your home using the same address, like http://yourName.noip.com...

Sign In or Register to comment.