本文整理汇总了Java中org.xbill.DNS.SimpleResolver.setPort方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleResolver.setPort方法的具体用法?Java SimpleResolver.setPort怎么用?Java SimpleResolver.setPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xbill.DNS.SimpleResolver
的用法示例。
在下文中一共展示了SimpleResolver.setPort方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reverseLookupByAddress
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
/**
* reverse lookup an IP address using a specified DNS host and port
*
* @param resolverHost name server hostname or IP address
* @param resolverPort name server port
* @param address the IP address to reverse lookup
* @return a comma separated list of names or an empty string when unable to resolve
*/
public String reverseLookupByAddress(String resolverHost, int resolverPort, InetAddress address) {
try {
SimpleResolver resolver = new SimpleResolver(resolverHost);
resolver.setPort(resolverPort);
Lookup lookup = new Lookup(fromAddress(address), PTR);
Record[] records = lookup.run();
if (records != null) {
List<String> addresses =
of(records)
.filter(it -> it instanceof PTRRecord)
.map(it -> ((PTRRecord) it).getTarget().toString())
.collect(toList());
return collectionToCommaDelimitedString(addresses);
} else {
return "";
}
} catch (UnknownHostException e) {
log.warn("unable to resolve using SRV record " + address, e);
return "";
}
}
示例2: testDnsJavaWithDnsServer
import org.xbill.DNS.SimpleResolver; //导入方法依赖的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: resolveHostByName
import org.xbill.DNS.SimpleResolver; //导入方法依赖的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 "";
}
}
示例4: testNoAnswer
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
@Test
@JUnitDNSServer(port=9153, zones={})
public void testNoAnswer() throws Exception {
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();
assertNotNull(answers);
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);
}
示例5: testNoAnswer
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
@Test
@JUnitDNSServer(port=9153, zones={})
public void testNoAnswer() throws Exception {
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);
}
示例6: resolveTextByName
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
/**
* resolves the TXT field for a given name using a specified DNS host and port. This is useful, for example,
* if you want to resolve abusers with: <a href="https://abusix.com/contactdb.html">https://abusix.com/contactdb.html</a>
*
* @param resolverHost name server hostname or IP address
* @param resolverPort name server port
* @param name the DNS name of the TXT record - the name to resolve
* @return the resolved text
*/
public String resolveTextByName(String resolverHost, int resolverPort, String name) {
try {
SimpleResolver resolver = new SimpleResolver(resolverHost);
resolver.setPort(resolverPort);
Lookup lookup = new Lookup(name, TXT);
Record[] records = lookup.run();
if (records != null) {
List<String> addresses =
of(records)
.filter(it -> it instanceof TXTRecord)
.map(it -> collectionToCommaDelimitedString(((TXTRecord) it).getStrings()))
.collect(toList());
return collectionToCommaDelimitedString(addresses);
} else {
return "";
}
} catch (UnknownHostException | TextParseException e) {
log.warn("unable to resolve using TXT record " + name, e);
return "";
}
}
示例7: resolveServiceByName
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
/**
* resolves an SRV 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 SRV record
* @return a comma separate list of ip:port, e.g: 1.2.3.4:8080,2.3.4.5:9090 or null when unable to resolve
*/
public String resolveServiceByName(String resolverHost, int resolverPort, String name) {
try {
SimpleResolver resolver = new SimpleResolver(resolverHost);
resolver.setPort(resolverPort);
return resolveSrvByName(resolver, name);
} catch (UnknownHostException e) {
log.warn("unable to resolve using SRV record " + name, e);
return null;
}
}
示例8: getResolver
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
private SimpleResolver getResolver() throws UnknownHostException {
final String skyDnsAddress = getEnv("SKYDNS_SERVER", "localhost");
final SimpleResolver resolver = new SimpleResolver(skyDnsAddress);
final String skyDnsPort = System.getenv("SKYDNS_PORT");
resolver.setPort(isNullOrEmpty(skyDnsPort) ? 53 : Integer.parseInt(skyDnsPort));
return resolver;
}
示例9: testDnsJavaResponse
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
@Test
public void testDnsJavaResponse() throws IOException {
final Lookup l = new Lookup("example.com");
final SimpleResolver resolver = new SimpleResolver("127.0.0.1");
resolver.setPort(9153);
l.setResolver(resolver);
l.run();
System.out.println("result: " + l.getResult());
if(l.getResult() == Lookup.SUCCESSFUL) {
System.out.println(l.getAnswers()[0].rdataToString());
}
assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
示例10: testDnsJavaQuadARecord
import org.xbill.DNS.SimpleResolver; //导入方法依赖的package包/类
@Test
public void testDnsJavaQuadARecord() throws IOException {
final Lookup l = new Lookup("ipv6.example.com", Type.AAAA);
final SimpleResolver resolver = new SimpleResolver("::1");
resolver.setPort(9153);
l.setResolver(resolver);
l.run();
System.out.println("result: " + l.getResult());
if(l.getResult() == Lookup.SUCCESSFUL) {
System.out.println(l.getAnswers()[0].rdataToString());
}
assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}