Results 1 to 7 of 7
  1. #1
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default How to get client Ipaddress using Applet

    Hai,

    How to get an ip address of a local machine?

    Thanks in advance.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is online now Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    810
    Rep Power
    6

    Default

    Hi,

    InetAddress addr = InetAddress.getLocalHost();
    System.out.println(addr.getHostAddress());

    -Regards
    Ramya
    Ramya:cool:

  3. #3
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Thanks for your reply.

    This code works fine, in normal java.

    I created one applet program, which will give me the ipaddress.

    Instead of giving, local machine's ipAddress, it is giving Localhost ip.

    For eg, my ipAddress is 172.16.0.37.

    But is giving me as, 127.0.0.1

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Please stick with a one thread. Do not post the same thread several times. Sorry I've to close the other thread.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by jasmu View Post
    Thanks for your reply.

    This code works fine, in normal java.

    I created one applet program, which will give me the ipaddress.

    Instead of giving, local machine's ipAddress, it is giving Localhost ip.

    For eg, my ipAddress is 172.16.0.37.

    But is giving me as, 127.0.0.1

    This cannot be happen, except one thing. Did you read the Java doc?

    Returns the local host.
    If there is a security manager, its checkConnect method is called with the local host name and -1 as its arguments to see if the operation is allowed. If the operation is not allowed, an InetAddress representing the loopback address is returned.

  6. #6
    jasmu is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Thanks for your reply,

    How to get that clientIP?

    i imported, the correct header file only,

    import java.net.InetAddress;


    i created one APPLET Program, in my local machine only.

    If i execute, it is giving 127.0.0.1.

    My IPAddress,172.16.0.37.


    Code is working in normal java program. Not working in Applet Program.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You say that when you run it as a console application, get the correct IP and not in the Applet?

    I think you are using IE. IE cannot do this with the default security level. Go to the security tab and find the option "Allow access to all IP address" and enable.

Similar Threads

  1. Applet with (label client side)?
    By Godsent in forum Java Applets
    Replies: 1
    Last Post: 04-30-2009, 10:46 AM
  2. ipaddress
    By tej in forum Networking
    Replies: 7
    Last Post: 04-25-2009, 06:07 PM
  3. IPAddress to Country
    By sandeeprao.techno in forum Advanced Java
    Replies: 2
    Last Post: 12-19-2008, 01:39 AM
  4. Replies: 2
    Last Post: 10-05-2008, 06:13 PM
  5. How to track client logout time and orignal ipaddress (not gateway) in java
    By psandeep in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-13-2008, 12:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •