The Artima Developer Community
Sponsored Link

Java Answers Forum
Java Applet

5 replies on 1 page. Most recent reply: Sep 15, 2003 11:57 PM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Kevin

Posts: 27
Nickname: quasi
Registered: Apr, 2003

Java Applet Posted: Sep 15, 2003 4:33 AM
Reply to this message Reply
Advertisement
Is there any way to log a user's IP using a applet when they log into a website.


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Java Applet Posted: Sep 15, 2003 6:24 AM
Reply to this message Reply
import java.net.*;
import java.io.*;
import java.applet.*;
 
public class GetClientIP extends Applet {
  public void init() {
    try {
     InetAddress thisIp =
        InetAddress.getLocalHost();
     System.out.println("IP:"+thisIp.getHostAddress());
     }
    catch(Exception e) {
     e.printStackTrace();
     }
    }
}
 


but i m not sure if it will give correct IP as i have not tested it

the logic behind not giving correct ip is that
Since applets run on the client, the IP is always 127.0.0.1 (localhost).

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Java Applet Posted: Sep 15, 2003 6:31 AM
Reply to this message Reply
and i was correct u cant get the real ip of client
http://java.sun.com/sfaq/index.html

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Java Applet Posted: Sep 15, 2003 6:33 AM
Reply to this message Reply
still not sure....try the code and tell if u get the real ip or not?

Kevin

Posts: 27
Nickname: quasi
Registered: Apr, 2003

Re: Java Applet Posted: Sep 15, 2003 11:50 PM
Reply to this message Reply
Is there any way to save this to a file or log it to a html file

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Java Applet Posted: Sep 15, 2003 11:57 PM
Reply to this message Reply
Hi Mausam,

I am not sure about Applet but I have worked with JSPs and I am sure in JSP real IP of the client can be obtained. Therefore I am gussing that there should be a way in applet too.

Flat View: This topic has 5 replies on 1 page
Topic: How a socket client can recover from Server Crash? Previous Topic   Next Topic Topic: List And Set

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use