-3

Possible Duplicate:
Get Client IP using just Javascript?

How can I retrieve/get the client IP address?

5
  • When the client connects, it must send you it's internal address which is can look up. If it doesn't you can't force it to do so. This is generally useless except for hacking to get an understand of an organizations internal network, which is why it is not generally available. Commented Dec 18, 2012 at 13:17
  • @BrMe atleast tell us, whether you got the solution or still you need some improvement in my solution. If no, then accept the answer. Commented Dec 18, 2012 at 14:25
  • I dont have any solution. look at ip-lookup.net. they display your local IP.How can I do that? Commented Dec 19, 2012 at 8:51
  • I want to get the internal IP of the client!!!all the answers are for the external IP Commented Dec 19, 2012 at 11:20
  • look in this site . there is LAN IP there. in all answerd i get just the WAN IP Commented Dec 19, 2012 at 11:26

1 Answer 1

3

If you need server side scripting, i mean Java code, then refer this

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;


public class IPAddress{
    public static void main(String[] a) {

        try {
            InetAddress thisIp = InetAddress.getLocalHost();
            System.out.print(thisIp.getHostAddress());     
        } catch (UnknownHostException ex) {
            Logger.getLogger(study.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

UPDATE

As you said, you need in javaScript. Please refer below code and let me know.

<html>
<head>
<script type="text/javascript" language="javascript">
  function myIP() {
    if (window.XMLHttpRequest) 
   xmlhttp = new XMLHttpRequest();
    else 
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    xmlhttp.open("GET","http://jsonip.appspot.com/",false);
    xmlhttp.send();

    hostipInfo = xmlhttp.responseText;
    obj = JSON.parse(hostipInfo);
    document.getElementById("IP").value=obj.ip;
    document.getElementById("ADDRESS").value=obj.address;
}
</script>
</head>
<body onload="myIP()">
IP :<input type="text" id="IP" name="IP" />
ADDRESS :<input type="text" id="ADDRESS" name="ADDRESS" />

</body>
</html>

You may also refer How to display client IP Address.

Sign up to request clarification or add additional context in comments.

23 Comments

This code is JAVA!i work with .net. someone told me to do that in Java,but in client side.
i didn't get you ?? what you exactly want?? in java or .net ?? This code code is working perfectly on my system. All i can do, is you let me know your exact requirement.
if i'm not wrong, you want the code for client side script not java code, which will return the LAN IP, isn't??
yes,thats exactly what I want.I found this , but there is no example code in this answere.
dude, you really need spoon feeding. you never read the answer carefully. the link, which you provide is showing the same thing getInetAddress() belongs to java code. You can find same thing in my code. If you gone through.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.