Jump to content

[SOLVED] Trouble getting users IP adress

- - - - -

  • Please log in to reply
4 replies to this topic

#1
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Hello! I'm in trouble(again)
Sorry for my qustions,but I'm still new in java and here i'm sure that I will get help from java pros.
I'm trying to get a users IP adress.I have the following code:


try {

InetAddress thisIp =InetAddress.getLocalHost();

lblIP.setText("IP:"+thisIp.getHostAddress());

}

catch(Exception e) {

e.printStackTrace();

}


It's compiling,without errors,but the output IP is not real....I mean,its just a random IP adress...

What I'm doing wrong...

Thanks in advance for any replay!

Edited by alex1, 05 February 2012 - 12:18 PM.


#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Random? Are you seeing an internal IP address?
it may look similar to : 127.x.x.x or 192.168.x.x

#3
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
its 192.168.x.x

But How can I see the real IP? :)

#4
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Check out this link from StackOverflow : networking - Getting the 'external' IP address in Java - Stack Overflow
In a nutshell, the following link: http://automation.wh...m/n09230945.asp is a page that contains 1 line of text. That text is your IP address.

So, create a connection to this page then read the contents.

#5
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Worked!!!

Thanks Lethal!!!! :thumbup1:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users