Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.frw.tangerino.web.ws;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import org.xbill.DNS.*;
- /*
- <dependency>
- <groupId>dnsjava</groupId>
- <artifactId>dnsjava</artifactId>
- <version>2.1.8</version>
- </dependency>
- */
- public class UsingDNS {
- public static void main(String[] args) {
- try {
- InetAddress address = InetAddress.getLocalHost();
- System.out.println("LOCAL ADDRESS : " + address.getHostAddress());
- System.out.println("LOCAL HOST : " + address.getHostName());
- InetAddress ipAddress = java.net.InetAddress.getByName("api.tangerino.com.br");
- String ip = ipAddress.getHostAddress();
- System.out.println("API IP : " + ip);
- final InetAddress ip2 = InetAddress.getByName("52.67.84.7");
- final byte[] bytes = ip2.getAddress();
- final String host = getHostByIPAddress(bytes);
- System.out.println("API HOST : " + host);
- } catch (UnknownHostException e) {
- System.out.println("Host NOT Avaialble");
- }
- }
- public static String getHostByIPAddress(byte[] addr) throws UnknownHostException {
- Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr));
- // OPEN DNS SERVERS
- //final String[] openDNS = new String[] {"208.67.222.222", "208.67.220.220"};
- // GOOGLE DNS SERVERS
- final String[] openDNS = new String[] {"8.8.8.8", "8.8.4.4"};
- final Resolver resolver = new ExtendedResolver(openDNS);
- final Lookup lookUp = new Lookup(name, Type.PTR);
- lookUp.setResolver(resolver);
- Record[] records = lookUp.run();
- if (records == null) {
- throw new UnknownHostException();
- }
- return ((PTRRecord) records[0]).getTarget().toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement