class InetAddress

hi, I have a little problem when I'm trying to check my hostname,
here is the code

server = new ServerSocket(4000,1);

System.out.println(server.getInetAddress().getHostName());  
// 0.0.0.0 <- ?

connection = server.accept();

System.out.println("Connected on "+ connection.getInetAddress().getHostName());
// Connected on SAPPHIRE

I need to have in my application my IP as well but I don't know how to get it.
I tried this

System.out.println("nom "+InetAddress.getLocalHost());

But it gives me my local hostname & IP,     //rockstar/192.168.1.4
but I need my IP to the Net     //217.136.10.198 for example

Thanks :-)
KouKiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>but I need my IP to the Net    

Why, as it happens?
0
KouKiAuthor Commented:


client = new Socket(ip, 4000);

So that the user can connect to my server !!
He has to know my IP,
and since I got a router, my hostname is my local address
0
DrWarezzCommented:
Ah, because you're on a network, you're retrieving your network IP, rather than your internet one.

I had this same problem ages ago -- and I came up with some code that logged on to: www.whatismyip.com, and extracted my IP from that page.

But, if you have a dedicated server somewhere, that you can run a java app on, then create a server socket on that, connect to it from your machine, and have the server send you your IP  ;)
 
there's bound to be an easier way I'm sure.

gL,
[r.D]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

DrWarezzCommented:
>"client = new Socket(ip, 4000);

So that the user can connect to my server !!
He has to know my IP,
and since I got a router, my hostname is my local address"

If the user has to connect to YOUR machine, how are you going to 'tell' the user what YOUR IP is anyways?

[r.D]
0
CEHJCommented:
This is not really a Java issue. What you need to do is to configure your network so it will allow this. Get it to do port forwarding to a port of your choice on the server
0
KouKiAuthor Commented:
> If the user has to connect to YOUR machine, how are you going to 'tell' the user what YOUR IP is anyways?

The servers are gonna put their ip's in a database (<- and that's why i need it),
then those will appear in a list and the clients have to double click on it ...

>But, if you have a dedicated server somewhere, that you can run a java app on, then create a server socket on that, connect to it from your machine, and have the server send you your IP  ;)

Thanks that should work

> Get it to do port forwarding to a port of your choice on the server

I didn't get this :-( ... how do you mean ?
0
CEHJCommented:
>>I didn't get this

What router are you using?
0
KouKiAuthor Commented:
a topcom router,
i know how to port forwarding,
but i dont understand the link with how i can get my IP ...
0
CEHJCommented:
If the router is also the gateway, give the gateway:x as the address and get it to port-forward to server:x
0
CEHJCommented:
Sorry - i'm losing concentration - forget that!
0
CEHJCommented:
What i was really trying to get at was not port forwarding, but NAT in relation to a particular port. My last comment could be read substituting 'NAT' for 'port-forward'
0
KouKiAuthor Commented:
Thanks,
I have no idea on how i can do this, but i'll try to get further information!
See you !
0
DrWarezzCommented:
:)
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.