Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

class InetAddress

Posted on 2004-10-25
14
Medium Priority
?
191 Views
Last Modified: 2010-03-31
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 :-)
0
Comment
Question by:KouKi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12402923
>>but I need my IP to the Net    

Why, as it happens?
0
 

Author Comment

by:KouKi
ID: 12403034


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
 
LVL 9

Accepted Solution

by:
DrWarezz earned 240 total points
ID: 12403814
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:DrWarezz
ID: 12403923
>"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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12403928
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
 

Author Comment

by:KouKi
ID: 12404306
> 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12404339
>>I didn't get this

What router are you using?
0
 

Author Comment

by:KouKi
ID: 12404399
a topcom router,
i know how to port forwarding,
but i dont understand the link with how i can get my IP ...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12404448
If the router is also the gateway, give the gateway:x as the address and get it to port-forward to server:x
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12404496
Sorry - i'm losing concentration - forget that!
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 63 total points
ID: 12410387
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
 

Author Comment

by:KouKi
ID: 12413935
Thanks,
I have no idea on how i can do this, but i'll try to get further information!
See you !
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12413952
:)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12413999
:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question