Getting Local IP address and HostName in Applet


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Getting Local IP address and HostName in Applet

  1. #1
    Ali Imran Guest

    Getting Local IP address and HostName in Applet


    Hello!

    I have tried to get the IP address and host name of the host running my Java
    applet using the following Java-Code:

    InetAddress inetadr = InetAddress.getLocalHost();
    System.out.println("LocalIP: " + inetadr.getHostAddress());
    System.out.println("LocalName: " + inetadr.getHostName());

    But I always get 127.0.0.1 and localhost is there any other way to determine
    the name and IP address of my localhost???

    Can anyone help me?



  2. #2
    Lim Wing Hoe Guest

    Re: Getting Local IP address and HostName in Applet

    The IP address 127.0.0.1 is a reserved IP address for local host. If you're
    connected to the internet and being assigned dynamically an IP address from
    your ISP, you may get another IP address.
    If you're not connected to the internet or local area network, 127.0.0.1
    will be the default IP address the code will return to you.

    --



    Best Regards,
    Wing Hoe
    ---------------------------------------------------------------
    Email1: winghoe@yahoo.com
    Email2: winghoe@hotmail.com
    ICQ no: 2213281
    www: http://pwp.maxis.net.my/winghoe
    ---------------------------------------------------------------


    Ali Imran <aimran@bigfoot.com> wrote in message
    news:395ee6c9$1@news.devx.com...
    >
    > Hello!
    >
    > I have tried to get the IP address and host name of the host running my

    Java
    > applet using the following Java-Code:
    >
    > InetAddress inetadr = InetAddress.getLocalHost();
    > System.out.println("LocalIP: " + inetadr.getHostAddress());
    > System.out.println("LocalName: " + inetadr.getHostName());
    >
    > But I always get 127.0.0.1 and localhost is there any other way to

    determine
    > the name and IP address of my localhost???
    >
    > Can anyone help me?
    >
    >




  3. #3
    Ali Imran Guest

    Re: Getting Local IP address and HostName in Applet


    "Lim Wing Hoe" <winghoe@yahoo.com> wrote:


    It is working fine on my machine but when I host it it shows
    localhost 127.0.0.1








    >The IP address 127.0.0.1 is a reserved IP address for local host. If you're
    >connected to the internet and being assigned dynamically an IP address from
    >your ISP, you may get another IP address.
    >If you're not connected to the internet or local area network, 127.0.0.1
    >will be the default IP address the code will return to you.
    >
    >--
    >
    >
    >
    >Best Regards,
    >Wing Hoe
    >---------------------------------------------------------------
    >Email1: winghoe@yahoo.com
    >Email2: winghoe@hotmail.com
    >ICQ no: 2213281
    >www: http://pwp.maxis.net.my/winghoe
    >---------------------------------------------------------------
    >
    >
    >Ali Imran <aimran@bigfoot.com> wrote in message
    >news:395ee6c9$1@news.devx.com...
    >>
    >> Hello!
    >>
    >> I have tried to get the IP address and host name of the host running my

    >Java
    >> applet using the following Java-Code:
    >>
    >> InetAddress inetadr = InetAddress.getLocalHost();
    >> System.out.println("LocalIP: " + inetadr.getHostAddress());
    >> System.out.println("LocalName: " + inetadr.getHostName());
    >>
    >> But I always get 127.0.0.1 and localhost is there any other way to

    >determine
    >> the name and IP address of my localhost???
    >>
    >> Can anyone help me?
    >>
    >>

    >
    >



  4. #4
    John Timney (MVP) Guest

    Re: Getting Local IP address and HostName in Applet

    your asking the applet to provide the localhost which will always be
    127.0.0.1, localhost is a loopback address for machines without networks.

    If you want the assigned IP address try requesting the assigned address by
    machine name

    InetAddress addr = InetAddress.getByName("myMachienName");

    Regards

    John Timney (MVP)


    Ali Imran <aimran@bigfoot.com> wrote in message
    news:395ee6c9$1@news.devx.com...
    >
    > Hello!
    >
    > I have tried to get the IP address and host name of the host running my

    Java
    > applet using the following Java-Code:
    >
    > InetAddress inetadr = InetAddress.getLocalHost();
    > System.out.println("LocalIP: " + inetadr.getHostAddress());
    > System.out.println("LocalName: " + inetadr.getHostName());
    >
    > But I always get 127.0.0.1 and localhost is there any other way to

    determine
    > the name and IP address of my localhost???
    >
    > Can anyone help me?
    >
    >




  5. #5
    Ali Imran Guest

    Re: Getting Local IP address and HostName in Applet


    I did that but still while I run on my machine and the server where I hosted
    that machine it is still get the loopback address.

    can I send the the files I made?

    Thanks.



    "John Timney (MVP)" <timneyj@btinternet.com> wrote:
    >your asking the applet to provide the localhost which will always be
    >127.0.0.1, localhost is a loopback address for machines without networks.
    >
    >If you want the assigned IP address try requesting the assigned address

    by
    >machine name
    >
    >InetAddress addr = InetAddress.getByName("myMachienName");
    >
    >Regards
    >
    >John Timney (MVP)
    >
    >
    >Ali Imran <aimran@bigfoot.com> wrote in message
    >news:395ee6c9$1@news.devx.com...
    >>
    >> Hello!
    >>
    >> I have tried to get the IP address and host name of the host running my

    >Java
    >> applet using the following Java-Code:
    >>
    >> InetAddress inetadr = InetAddress.getLocalHost();
    >> System.out.println("LocalIP: " + inetadr.getHostAddress());
    >> System.out.println("LocalName: " + inetadr.getHostName());
    >>
    >> But I always get 127.0.0.1 and localhost is there any other way to

    >determine
    >> the name and IP address of my localhost???
    >>
    >> Can anyone help me?
    >>
    >>

    >
    >



  6. #6
    Paul Clapham Guest

    Re: Getting Local IP address and HostName in Applet

    It's really better if you don't post the same question in multiple forums.
    That way you don't waste the time of anyone who seriously wants to consider
    your question.

    Ali Imran <aimran@bigfoto.com> wrote in message
    news:3962de0b$1@news.devx.com...
    >
    > I did that but still while I run on my machine and the server where I

    hosted
    > that machine it is still get the loopback address.
    >
    > can I send the the files I made?
    >
    > Thanks.
    >
    >
    >
    > "John Timney (MVP)" <timneyj@btinternet.com> wrote:
    > >your asking the applet to provide the localhost which will always be
    > >127.0.0.1, localhost is a loopback address for machines without networks.
    > >
    > >If you want the assigned IP address try requesting the assigned address

    > by
    > >machine name
    > >
    > >InetAddress addr = InetAddress.getByName("myMachienName");
    > >
    > >Regards
    > >
    > >John Timney (MVP)
    > >
    > >
    > >Ali Imran <aimran@bigfoot.com> wrote in message
    > >news:395ee6c9$1@news.devx.com...
    > >>
    > >> Hello!
    > >>
    > >> I have tried to get the IP address and host name of the host running my

    > >Java
    > >> applet using the following Java-Code:
    > >>
    > >> InetAddress inetadr = InetAddress.getLocalHost();
    > >> System.out.println("LocalIP: " + inetadr.getHostAddress());
    > >> System.out.println("LocalName: " + inetadr.getHostName());
    > >>
    > >> But I always get 127.0.0.1 and localhost is there any other way to

    > >determine
    > >> the name and IP address of my localhost???
    > >>
    > >> Can anyone help me?
    > >>
    > >>

    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center