Skip to content

Instantly share code, notes, and snippets.

@asdaraujo
Created December 18, 2020 13:30
Show Gist options
  • Save asdaraujo/12ddbca5d0d777d28be9536d4ad0102e to your computer and use it in GitHub Desktop.
Save asdaraujo/12ddbca5d0d777d28be9536d4ad0102e to your computer and use it in GitHub Desktop.
Java reverse DNS name resolution
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
public class ResolverHelper {
public static void main(String[] args) throws UnknownHostException {
InetAddress ia = InetAddress.getByName(args[0]);
InetSocketAddress isa = new InetSocketAddress(args[0], 12345);
System.out.println(ia.getCanonicalHostName());
System.out.println(isa.getAddress().getCanonicalHostName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment