This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes How to get DNS name and IP Address with Java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply locked New topic

How to get DNS name and IP Address with Java code

SP Nam
Ranch Hand

Joined: Oct 15, 2003
Posts: 41
How can I get my DNS servername and IPAddress, by just running a java program from command prompt, code help please
Vinod Chandana
Ranch Hand

Joined: Aug 26, 2003
Posts: 59
Try InetAddress.getLocalHost().getHostName() and InetAddress.getLocalHost().getHostAddress(). This will give u both name and the address of the localhost. Hope this helps. If not give me a message.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

I'm closing this thread, as it's a duplicate of this one, where the question has already been answered. Please post followups there.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: How to get DNS name and IP Address with Java code
It's not a secret anymore!