本文整理匯總了Java中org.xbill.DNS.TextParseException類的典型用法代碼示例。如果您正苦於以下問題:Java TextParseException類的具體用法?Java TextParseException怎麽用?Java TextParseException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TextParseException類屬於org.xbill.DNS包,在下文中一共展示了TextParseException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolve
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
/**
* Attempts to resolve an SMTP server address, given the destination e-mail address.
*
* @param email The e-mail address used for the lookup.
* @return An optional, potentially containing
*/
protected Optional<String> resolve(String email) {
Optional<String> domainOptional = extractDomain(email);
if (!domainOptional.isPresent()) {
return Optional.empty();
}
String mailDomain = domainOptional.get();
try {
Lookup dnsLookup = new Lookup(mailDomain, Type.MX);
List<Record> records = Arrays.asList(dnsLookup.run());
if (records.isEmpty()) {
return Optional.empty();
}
return chooseBestRecord(records);
} catch (TextParseException e) {
e.printStackTrace();
}
return Optional.empty();
}
示例2: testDnsJavaWithDnsServer
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
@Test
public void testDnsJavaWithDnsServer() throws TextParseException, UnknownHostException {
final Lookup l = new Lookup("example.com", Type.AAAA);
final SimpleResolver resolver = new SimpleResolver("::1");
resolver.setPort(9153);
l.setResolver(resolver);
l.run();
System.out.println("result: " + l.getResult());
final Record[] answers = l.getAnswers();
assertEquals(answers.length, 1);
final Record record = answers[0];
System.err.println(record.getTTL());
if(l.getResult() == Lookup.SUCCESSFUL) {
System.out.println(l.getAnswers()[0].rdataToString());
}
assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
示例3: beforeConsoleCrossDcServerTest
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
@Before
public void beforeConsoleCrossDcServerTest(){
crossDcClusterServer = new ConsoleCrossDcServer(){
@Override
protected List<String> lookUpCname(String domain) throws TextParseException {
return cnames;
}
};
crossDcClusterServer.setConsoleConfig(consoleConfig);
crossDcClusterServer.setCheckIntervalMilli(checkIntervalMilli);
cnames.add("cname1");
HashMap<String, String> cnameToDc = new HashMap<>();
cnameToDc.put("cname1", "jq");
cnameToDc.put("cname2", "oy");
DefaultFoundationService.setDataCenter("jq");
when(consoleConfig.getConsoleDomain()).thenReturn("xpipe");
when(consoleConfig.getConsoleCnameToDc()).thenReturn(cnameToDc);
}
示例4: lookupSRVRecords
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
@Override
public List<SRVRecord> lookupSRVRecords(String name) throws TextParseException {
List<SRVRecord> res = new ArrayList<SRVRecord>();
Lookup lookup = new Lookup(name, Type.SRV);
Record[] recs = lookup.run();
if (recs == null)
return res;
for (Record record : recs) {
org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
if (srvRecord != null && srvRecord.getTarget() != null) {
String host = srvRecord.getTarget().toString();
int port = srvRecord.getPort();
int priority = srvRecord.getPriority();
int weight = srvRecord.getWeight();
SRVRecord r = new SRVRecord(host, port, priority, weight);
res.add(r);
}
}
return res;
}
示例5: resolveHostByName
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
/**
* resolves an A record by its name using a specified DNS host and port
*
* @param resolverHost name server hostname or IP address
* @param resolverPort name server port
* @param name the DNS name of the A record - the name to resolve
* @return a comma separated list of IP addresses or an empty string when unable to resolve
*/
public String resolveHostByName(String resolverHost, int resolverPort, String name) {
try {
SimpleResolver resolver = new SimpleResolver(resolverHost);
resolver.setPort(resolverPort);
Lookup lookup = new Lookup(name, A);
Record[] records = lookup.run();
if (records != null) {
List<String> addresses =
of(records)
.filter(it -> it instanceof ARecord)
.map(it -> ((ARecord) it).getAddress().getHostAddress())
.collect(toList());
return collectionToCommaDelimitedString(addresses);
} else {
return "";
}
} catch (UnknownHostException | TextParseException e) {
log.warn("unable to resolve using A record " + name, e);
return "";
}
}
示例6: resolveSrvByName
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
private String resolveSrvByName(Resolver resolver, String name) {
try {
Lookup lookup = new Lookup(name, SRV);
if (resolver != null) {
lookup.setResolver(resolver);
}
Record[] records = lookup.run();
if (records == null) {
return null;
}
return of(records)
.filter(it -> it instanceof SRVRecord)
.map(srv -> resolveHostByName(resolver, ((SRVRecord) srv).getTarget()) + ":" + ((SRVRecord) srv).getPort())
.distinct()
.collect(joining(","));
} catch (TextParseException e) {
log.warn("unable to resolve using SRV record " + name, e);
return null;
}
}
示例7: testCompareSamePriorityWeightAndDifferentHost
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
@Test
public void testCompareSamePriorityWeightAndDifferentHost () throws TextParseException {
ServiceRecord svc1 = ServiceRecord.build( DiscoveryRecordUtil.createSrvRecord( "host1.com.", 1800, 0, 10, 3600 ) );
ServiceRecord svc2 = ServiceRecord.build( DiscoveryRecordUtil.createSrvRecord( "host2.com.", 1800, 0, 10, 3600 ) );
ServiceRecord svc3 = ServiceRecord.build( DiscoveryRecordUtil.createSrvRecord( "host3.com.", 1800, 0, 10, 3600 ) );
TextRecord txt1 = TextRecord.build( DiscoveryRecordUtil.createTxtRecord( "txt1", 3600 ) );
TextRecord txt2 = TextRecord.build( DiscoveryRecordUtil.createTxtRecord( "txt1", 3600 ) );
TextRecord txt3 = TextRecord.build( DiscoveryRecordUtil.createTxtRecord( "txt1", 3600 ) );
ServiceInstance svcInst1 = new ServiceInstance( serviceTypeCoap, svc1, txt1 );
ServiceInstance svcInst2 = new ServiceInstance( serviceTypeCoap, svc2, txt2 );
ServiceInstance svcInst3 = new ServiceInstance( serviceTypeCoap, svc3, txt3 );
List<ServiceInstance> list = new ArrayList<ServiceInstance>( 3 );
list.add( svcInst2 );
list.add( svcInst3 );
list.add( svcInst1 );
Collections.sort( list );
Assert.assertTrue( "First element in the list should be svcInst1", list.get( 0 ).equals( svcInst1 ) );
Assert.assertTrue( "Second element in the list should be svcInst2", list.get( 1 ).equals( svcInst2 ) );
Assert.assertTrue( "Third element in the list should be svcInst3", list.get( 2 ).equals( svcInst3 ) );
}
示例8: testCompareSamePriorityWeightHostAndDifferentPort
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
@Test
public void testCompareSamePriorityWeightHostAndDifferentPort () throws TextParseException {
ServiceRecord svc1 = ServiceRecord.build( DiscoveryRecordUtil.createSrvRecord( "host.com.", 1800, 0, 10, 3600 ) );
ServiceRecord svc2 = ServiceRecord.build( DiscoveryRecordUtil.createSrvRecord( "host.com.", 1801, 0, 10, 3600 ) );
ServiceRecord svc3 = ServiceRecord.build( DiscoveryRecordUtil.createSrvRecord( "host.com.", 1802, 0, 10, 3600 ) );
TextRecord txt1 = TextRecord.build( DiscoveryRecordUtil.createTxtRecord( "txt1", 3600 ) );
TextRecord txt2 = TextRecord.build( DiscoveryRecordUtil.createTxtRecord( "txt1", 3600 ) );
TextRecord txt3 = TextRecord.build( DiscoveryRecordUtil.createTxtRecord( "txt1", 3600 ) );
ServiceInstance svcInst1 = new ServiceInstance( serviceTypeCoap, svc1, txt1 );
ServiceInstance svcInst2 = new ServiceInstance( serviceTypeCoap, svc2, txt2 );
ServiceInstance svcInst3 = new ServiceInstance( serviceTypeCoap, svc3, txt3 );
List<ServiceInstance> list = new ArrayList<ServiceInstance>( 3 );
list.add( svcInst2 );
list.add( svcInst3 );
list.add( svcInst1 );
Collections.sort( list );
Assert.assertTrue( "First element in the list should be svcInst1", list.get( 0 ).equals( svcInst1 ) );
Assert.assertTrue( "Second element in the list should be svcInst2", list.get( 1 ).equals( svcInst2 ) );
Assert.assertTrue( "Third element in the list should be svcInst3", list.get( 2 ).equals( svcInst3 ) );
}
示例9: getARecord
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
public static List<ForwardLookupResult> getARecord(String hostName, String domainName) throws TextParseException {
List<ForwardLookupResult> entries = null;
if (hostName != null && !hostName.isEmpty() && domainName != null && !domainName.isEmpty()) {
Record[] recs = new Lookup(hostName, Type.A).run();
if (recs != null) {
if (recs.length > 0) {
entries = new ArrayList<>();
for (Record record : recs) {
ForwardLookupResult foundSubDomain = new ForwardLookupResult(domainName);
foundSubDomain.setHostName(hostName);
String ipAddress = ((ARecord) record).getAddress().getHostAddress();
foundSubDomain.setIpAddress(ipAddress);
foundSubDomain.setLookupType("A");
entries.add(foundSubDomain);
}
}
}
}
return entries;
}
示例10: getAAAARecord
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
public static List<ForwardLookupResult> getAAAARecord(String hostName, String domainName) throws TextParseException {
List<ForwardLookupResult> entries = null;
if (hostName != null && !hostName.isEmpty() && domainName != null && !domainName.isEmpty()) {
Record[] recs = new Lookup(hostName, Type.AAAA).run();
if (recs != null) {
if (recs.length > 0) {
entries = new ArrayList<>();
for (Record record : recs) {
ForwardLookupResult foundSubDomain = new ForwardLookupResult(domainName);
foundSubDomain.setHostName(hostName);
String ipAddress = ((AAAARecord) record).getAddress().getHostAddress();
foundSubDomain.setIpAddress(ipAddress);
foundSubDomain.setLookupType("A");
entries.add(foundSubDomain);
}
}
}
}
return entries;
}
示例11: addHostFromUrl
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
@Override
public void addHostFromUrl(String url, String baseUrl) {
try {
URL aUrl = new URL(url);
URL sUrl = new URL(baseUrl);
String domain = NetworkTools.getDomainFromHost(aUrl.getHost());
YileResult res = new YileResult(domain);
res.setHostName(aUrl.getHost());
res.setSource(sUrl.getHost());
res.setUrl(url);
try {
String name = domain.split("\\.", 2)[0];
String tld = domain.split("\\.", 2)[1];
res.setRegistrant(NetworkTools.getHostNameWhoisResult(name, tld, true));
res.setIPAddress(NetworkTools.getIpFromHost(aUrl.getHost()).get(0));
} catch (TextParseException tpe) {
Logger.getLogger("yileController.yileWorker.addHostFromUrl").log(Level.SEVERE, null, tpe);
}
addResult(res);
} catch (MalformedURLException ex) {
Logger.getLogger("yileController.yileWorker.addHostFromUrl").log(Level.SEVERE, null, ex);
}
}
示例12: getARecord
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
public static List<ARecordResult> getARecord(String hostName) throws TextParseException {
List<ARecordResult> entries = null;
Record[] recs = new Lookup(hostName, Type.A).run();
if (recs != null) {
if (recs.length > 0) {
entries = new ArrayList<>();
for (Record record : recs) {
ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName));
foundSubDomain.setHostName(hostName);
String ipAddress = ((ARecord) record).getAddress().getHostAddress();
foundSubDomain.setIpAddress(ipAddress);
foundSubDomain.setLookupType("A");
entries.add(foundSubDomain);
}
}
}
return entries;
}
示例13: getDomainFromHost
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
public static String getDomainFromHost(String host) {
String tmpHost = host;
if (host.isEmpty()) {
return "";
}
while (true) {
try {
if (!tmpHost.startsWith("www.")) {
Record[] recs = new Lookup(tmpHost, Type.SOA).run();
if (recs != null) {
return tmpHost;
}
}
if (tmpHost.contains(".")) {
tmpHost = tmpHost.split("\\.", 2)[1];
} else {
break;
}
} catch (TextParseException ex) {
Logger.getLogger("networkTools.getDomainFromHost").log(Level.SEVERE, null, ex);
break;
}
}
return "";
}
示例14: getARecord
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
public List<ARecordResult> getARecord(String hostName) throws TextParseException {
List<ARecordResult> entries = null;
Record[] recs = new Lookup(hostName, Type.A).run();
if (recs != null) {
if (recs.length > 0) {
entries = new ArrayList<>();
for (Record record : recs) {
ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName));
foundSubDomain.setHostName(hostName);
String ipAddress = ((ARecord) record).getAddress().getHostAddress();
foundSubDomain.setIpAddress(ipAddress);
foundSubDomain.setLookupType("A");
entries.add(foundSubDomain);
}
}
}
return entries;
}
示例15: getReverseIPName
import org.xbill.DNS.TextParseException; //導入依賴的package包/類
public static Name getReverseIPName(final InetAddress adr, final Name postfix)
{
final byte[] addr = adr.getAddress();
final StringBuilder sb = new StringBuilder();
if (addr.length == 4)
for (int i = addr.length - 1; i >= 0; i--)
{
sb.append(addr[i] & 0xFF);
if (i > 0)
sb.append(".");
}
else
{
final int[] nibbles = new int[2];
for (int i = addr.length - 1; i >= 0; i--)
{
nibbles[0] = (addr[i] & 0xFF) >> 4;
nibbles[1] = addr[i] & 0xFF & 0xF;
for (int j = nibbles.length - 1; j >= 0; j--)
{
sb.append(Integer.toHexString(nibbles[j]));
if (i > 0 || j > 0)
sb.append(".");
}
}
}
try
{
return Name.fromString(sb.toString(), postfix);
}
catch (final TextParseException e)
{
throw new IllegalStateException("name cannot be invalid");
}
}