0% found this document useful (0 votes)
31 views2 pages

Java DNS Lookup Tool Implementation

The document contains a Java program that implements a DNS lookup tool. It prompts the user to enter a domain name or IP address and retrieves the corresponding hostname or IP address. The program also includes a utility method to determine if the input is an IP address based on its format.

Uploaded by

Mayur Kamble
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Java DNS Lookup Tool Implementation

The document contains a Java program that implements a DNS lookup tool. It prompts the user to enter a domain name or IP address and retrieves the corresponding hostname or IP address. The program also includes a utility method to determine if the input is an IP address based on its format.

Uploaded by

Mayur Kamble
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;

import [Link];

public class DNSLookup {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("=== DNS Lookup Tool ===");

[Link]("Enter a domain name or IP address: ");

String input = [Link]().trim();

try {

// Check if input is IP or domain

InetAddress address = null;

if (isIPAddress(input)) {

// Input is IP — get hostname

address = [Link](input);

[Link]("Host name for IP (" + input + "): " +


[Link]());

} else {

// Input is domain — get IP

address = [Link](input);

[Link]("IP address for host (" + input + "): " +


[Link]());

} catch (UnknownHostException e) {

[Link]("Lookup failed: " + [Link]());

[Link]();

}
// Utility method to check if input looks like an IP address

private static boolean isIPAddress(String input) {

return [Link]("^\\d+\\.\\d+\\.\\d+\\.\\d+$");

You might also like