Java Code Examples for org.xbill.DNS.Name#fromConstantString()
The following examples show how to use
org.xbill.DNS.Name#fromConstantString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Output.java From helios with Apache License 2.0 | 6 votes |
public static String shortHostname(final String host) { final Name root = Name.fromConstantString("."); final Name hostname; try { hostname = Name.fromString(host, root); } catch (TextParseException e) { throw new IllegalArgumentException("Invalid hostname '" + host + "'"); } final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig(); if (currentConfig != null) { final Name[] searchPath = currentConfig.searchPath(); if (searchPath != null) { for (final Name domain : searchPath) { if (hostname.subdomain(domain)) { return hostname.relativize(domain).toString(); } } } } return hostname.toString(); }
Example 2
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 5 votes |
public static Long getASN(final InetAddress adr) { try { final Name postfix; if (adr instanceof Inet6Address) postfix = Name.fromConstantString("origin6.asn.cymru.com"); else postfix = Name.fromConstantString("origin.asn.cymru.com"); final Name name = getReverseIPName(adr, postfix); System.out.println("lookup: " + name); final Lookup lookup = new Lookup(name, Type.TXT); lookup.setResolver(new SimpleResolver()); lookup.setCache(null); final Record[] records = lookup.run(); if (lookup.getResult() == Lookup.SUCCESSFUL) for (final Record record : records) if (record instanceof TXTRecord) { final TXTRecord txt = (TXTRecord) record; @SuppressWarnings("unchecked") final List<String> strings = txt.getStrings(); if (strings != null && !strings.isEmpty()) { final String result = strings.get(0); final String[] parts = result.split(" ?\\| ?"); if (parts != null && parts.length >= 1) return new Long(parts[0]); } } } catch (final Exception e) { } return null; }
Example 3
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 5 votes |
public static String getASName(final long asn) { try { final Name postfix = Name.fromConstantString("asn.cymru.com."); final Name name = new Name(String.format("AS%d", asn), postfix); System.out.println("lookup: " + name); final Lookup lookup = new Lookup(name, Type.TXT); lookup.setResolver(new SimpleResolver()); lookup.setCache(null); final Record[] records = lookup.run(); if (lookup.getResult() == Lookup.SUCCESSFUL) for (final Record record : records) if (record instanceof TXTRecord) { final TXTRecord txt = (TXTRecord) record; @SuppressWarnings("unchecked") final List<String> strings = txt.getStrings(); if (strings != null && !strings.isEmpty()) { System.out.println(strings); final String result = strings.get(0); final String[] parts = result.split(" ?\\| ?"); if (parts != null && parts.length >= 1) return parts[4]; } } } catch (final Exception e) { } return null; }
Example 4
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 5 votes |
public static String getAScountry(final long asn) { try { final Name postfix = Name.fromConstantString("asn.cymru.com."); final Name name = new Name(String.format("AS%d", asn), postfix); System.out.println("lookup: " + name); final Lookup lookup = new Lookup(name, Type.TXT); lookup.setResolver(new SimpleResolver()); lookup.setCache(null); final Record[] records = lookup.run(); if (lookup.getResult() == Lookup.SUCCESSFUL) for (final Record record : records) if (record instanceof TXTRecord) { final TXTRecord txt = (TXTRecord) record; @SuppressWarnings("unchecked") final List<String> strings = txt.getStrings(); if (strings != null && !strings.isEmpty()) { final String result = strings.get(0); final String[] parts = result.split(" ?\\| ?"); if (parts != null && parts.length >= 1) return parts[1]; } } } catch (final Exception e) { } return null; }