-3

Possible Duplicate:
Get Client IP using just Javascript?

How can I retrieve/get the client IP address?

Community
  • 1
  • 1
BrMe
  • 315
  • 2
  • 8
  • 22
  • 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. – Peter Lawrey Dec 18 '12 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. – Ravi Dec 18 '12 at 14:25
  • I dont have any solution. look at http://www.ip-lookup.net/. they display your local IP.How can I do that? – BrMe Dec 19 '12 at 08:51
  • I want to get the internal IP of the client!!!all the answers are for the external IP – BrMe Dec 19 '12 at 11:20
  • look in [this site](http://www.ip-lookup.net/) . there is LAN IP there. in all answerd i get just the WAN IP – BrMe Dec 19 '12 at 11:26

1 Answers1

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.

Ravi
  • 30,829
  • 42
  • 119
  • 173
  • This code is JAVA!i work with .net. someone told me to do that in Java,but in client side. – BrMe Dec 19 '12 at 08:54
  • 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. – Ravi Dec 19 '12 at 08:58
  • if i'm not wrong, you want the code for client side script not java code, which will return the LAN IP, isn't?? – Ravi Dec 19 '12 at 09:01
  • yes,thats exactly what I want.I found [this](http://stackoverflow.com/questions/8959466/how-to-get-client-ip-address) , but there is no example code in this answere. – BrMe Dec 19 '12 at 09:04
  • be clear about your requirement. According to my understanding i will update your question and let me know, whether you want that. – Ravi Dec 19 '12 at 09:06
  • no problems!I want to get tyhe local IP(LAN) of client like in [THIS SITE](http://www.ip-lookup.net/) ! I know that I have to do that in javascript but i dont know hoe. – BrMe Dec 19 '12 at 09:09
  • 1
    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. – Ravi Dec 19 '12 at 09:10
  • ok!but I use .net ! and this code in Java!how can i use it? – BrMe Dec 19 '12 at 09:16
  • this is painful to watch... its like seeing a dog dig up a dinosaur. – Jeremy Thompson Dec 19 '12 at 10:06
  • dear @coders, this is what i get :"You are visiting from: IP Address: 62.219.243.155 Host: 62.219.243.155" . it is NOT my LAN IP. it is my external IP – BrMe Dec 19 '12 at 10:26
  • @coders , do you understand the problem? – BrMe Dec 19 '12 at 10:44
  • Do you have another suggestion for me? – BrMe Dec 19 '12 at 11:21
  • Yes, got it, what you are saying, perhaps, you might not be in LAN. Are sure, you are connected through LAN ?? – Ravi Dec 19 '12 at 11:26
  • Yes,I am sure ! in [www.ip-lookup.net](http://www.ip-lookup.net/) I can see teh LAN IP – BrMe Dec 19 '12 at 11:32
  • Do you have any solution for me? – BrMe Dec 19 '12 at 12:05
  • can you tell me your LAN IP ?? – Ravi Dec 19 '12 at 12:05
  • my LAN IP :192.168.91.4. How can it help you? – BrMe Dec 19 '12 at 12:07
  • i was getting sure about your LAN IP. – Ravi Dec 19 '12 at 12:11
  • Still getting the same.IP = :62.219.243.155 and Address = 62.219.243.155 – BrMe Dec 19 '12 at 13:26
  • so last thing what i can tell you that, you can only do this thing using client side script. For further, you need server side script i.e. `java` or `.net` or anyother. So, according to your current question. This would be the solution. If you need solution for further. Then, post your question again for server side script according to your requirement. For now, accept this answer, since this will be helpful in case of client side script. – Ravi Dec 19 '12 at 13:43
  • OK.I will accept the answere.but you know how to do that in .net? – BrMe Dec 19 '12 at 13:47
  • Don't forget to tag `.net` in your next question, and also never do irrelevant tagging in your question. That creates the confusion. – Ravi Dec 19 '12 at 13:52
  • since, i would not be able to verify (i mean currently, i don't have IIS server). But, i will suggest you, better, you should search some code in google and use those snippet in your next question. It will be helpful to get your answer as soon as possible. – Ravi Dec 19 '12 at 13:55