How to resolve HostName to Address using Java? - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

demo-image

How to resolve HostName to Address using Java?

Share This
Demo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.net.*;
public class Demo {
public static void main(String args[]) {
if (args.length != 1) {
System.err.println ("Syntax - Demo host");
System.exit(0);
}
System.out.println ("Resolving " + args[0]);
try {
InetAddress addr = InetAddress.getByName(args[0]);
System.out.println ("IP address : " + addr.getHostAddress() );
System.out.println ("Hostname : " + addr.getHostName());
} catch (UnknownHostException e) {
System.out.println ("Error - unable to resolve hostname" );
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Happy Exploring!

Comment Using!!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.