Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How t o Find Host Name and Port Number  RSS feed

 
K Seshan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have written an application which needs dynamic generation of URL.I need to know if there's a way to get the hostname and port number of the machine which this application is going to be invoked.

eg; http://hostname ort/emx/emxLogin.jsp

I think for getting hostname i can use the following code

InetAddress localhost = InetAddress.getLocalHost();

My problem is how to get the port number on which this application is listening.

Your help is greatly appreciated i this regard.Thanks in Advance
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K Seshan:

I think for getting hostname i can use the following code
InetAddress localhost = InetAddress.getLocalHost();

All that would get you is localhost (i.e. 127.0.0.1, the computer you are running on).
You don't need the host name. You can use an IP address just the same. As for the port, short of a port scan there's no way to find out. That's why there's a list of commonly used ports.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!