本文整理汇总了Java中org.xbill.DNS.Message.newQuery方法的典型用法代码示例。如果您正苦于以下问题:Java Message.newQuery方法的具体用法?Java Message.newQuery怎么用?Java Message.newQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xbill.DNS.Message
的用法示例。
在下文中一共展示了Message.newQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dnsLookup
import org.xbill.DNS.Message; //导入方法依赖的package包/类
/**
* Dns lookup more efficient than the INetAddress.getHostName(ip)
*
* @param hostIp
* @return
* @throws IOException
*/
public String dnsLookup(final String hostIp) {
try {
final Name name = ReverseMap.fromAddress(hostIp);
final int type = Type.PTR;
final int dclass = DClass.IN;
final Record rec = Record.newRecord(name, type, dclass);
final Message query = Message.newQuery(rec);
final Message response = _resolver.send(query);
final Record[] answers = response.getSectionArray(Section.ANSWER);
if (answers.length > 0) {
String ret = answers[0].rdataToString();
if (ret.endsWith(".")) {
ret = ret.substring(0, ret.length() - 1);
}
return ret;
}
} catch (final IOException e) {
LOGGER.warn("Failed to resolve hostname for " + hostIp, e);
}
return UNKNOWN_HOST;
}
示例2: toRecord
import org.xbill.DNS.Message; //导入方法依赖的package包/类
/**
* @param ip, like "192.168.1.1"
* @return the complete DNS record for that IP.
*/
@Converter
public static Record toRecord(String ip) throws IOException {
Resolver res = new ExtendedResolver();
Name name = ReverseMap.fromAddress(ip);
int type = Type.PTR;
int dclass = DClass.IN;
Record rec = Record.newRecord(name, type, dclass);
Message query = Message.newQuery(rec);
Message response = res.send(query);
Record[] answers = response.getSectionArray(Section.ANSWER);
if (answers.length == 0) {
return null;
} else {
return answers[0];
}
}
示例3: reverseDnsLookupUsingDnsJavaSimpleResolver
import org.xbill.DNS.Message; //导入方法依赖的package包/类
private static String reverseDnsLookupUsingDnsJavaSimpleResolver(long ipAddress) throws IOException {
String result = null;
byte[] address = convertLongAddressToBuf(ipAddress);
Name name = ReverseMap.fromAddress(InetAddress.getByAddress(address));
Record record = Record.newRecord(name, Type.PTR, DClass.IN);
Message query = Message.newQuery(record);
Message response = simpleResolver.send(query);
Record[] answers = response.getSectionArray(Section.ANSWER);
if (answers.length != 0) {
// If PTR-record exists this will be at index 1 or above (more than one PTR-record may exist)
Record answer = (answers.length > 1) ? answers[1] : answers[0];
result = answer.rdataToString();
// remove trailing "."
result = result.endsWith(".") ? result.substring(0, result.length() - 1) : result;
} else {
throw new IOException("Empty DNS response.");
}
return result;
}
示例4: makeQuery
import org.xbill.DNS.Message; //导入方法依赖的package包/类
public static synchronized Message makeQuery(String nameString, int id) throws TextParseException {
Name name = Name.fromString(nameString, Name.root);
Record question = Record.newRecord(name, Type.A, DClass.ANY);
Message query = Message.newQuery(question);
query.getHeader().setID(id);
return query;
}
示例5: testDnsQuery
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testDnsQuery() throws Exception {
Message message = Message.newQuery(new ARecord(new Name("notblocked.example.com."),
0x01,
3600,
Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
));
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastResponse);
assertNotNull(mockEventLoop.lastOutgoing);
assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
}
示例6: before
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Before
public void before() throws Exception {
simpleQuery =
Message.newQuery(Record.newRecord(Name.fromString("example.com."), Type.A, DClass.IN));
expectedResponse = responseMessageWithCode(simpleQuery, Rcode.NOERROR);
when(mockFactory.createSocket(InetAddress.getByName(UPDATE_HOST), DnsMessageTransport.DNS_PORT))
.thenReturn(mockSocket);
resolver = new DnsMessageTransport(mockFactory, UPDATE_HOST, Duration.ZERO);
}
示例7: process
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class);
SimpleResolver resolver = new SimpleResolver(server);
int type = Type.value(exchange.getIn().getHeader(DnsConstants.DNS_TYPE, String.class));
if (type == -1) {
// default: if unparsable value given, use A.
type = Type.A;
}
String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class);
if (dclassValue == null) {
dclassValue = "";
}
int dclass = DClass.value(dclassValue);
if (dclass == -1) {
// by default, value is IN.
dclass = DClass.IN;
}
Name name = Name.fromString(exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class), Name.root);
Record rec = Record.newRecord(name, type, dclass);
Message query = Message.newQuery(rec);
Message response = resolver.send(query);
exchange.getIn().setBody(response);
}
示例8: process
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
SimpleResolver resolver = new SimpleResolver();
int type = Type.TXT;
Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root);
Record rec = Record.newRecord(name, type, DClass.IN);
Message query = Message.newQuery(rec);
Message response = resolver.send(query);
Record[] records = response.getSectionArray(Section.ANSWER);
if (records.length > 0) {
exchange.getIn().setBody(records[0].rdataToString());
} else {
exchange.getIn().setBody(null);
}
}
示例9: messageWithRCode
import org.xbill.DNS.Message; //导入方法依赖的package包/类
private Message messageWithRCode(String query, int rcode) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
result.getHeader().setRcode(rcode);
return result;
}
示例10: messageWithNodes
import org.xbill.DNS.Message; //导入方法依赖的package包/类
private Message messageWithNodes(String query, Iterable<String> names) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
for (String name1 : names){
result.addRecord(new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)), Section.ANSWER);
}
return result;
}
示例11: testDsNodataFromWildcardNsecChild
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testDsNodataFromWildcardNsecChild() throws IOException {
Message m = Message.newQuery(Record.newRecord(Name.fromString("www.x.c.ingotronic.ch."), Type.A, DClass.IN));
m.addRecord(new ARecord(Name.fromString("www.x.c.ingotronic.ch."), DClass.IN, 300, InetAddress.getLocalHost()), Section.ANSWER);
add("www.x.c.ingotronic.ch./A", m);
Message response = resolver.send(createMessage("www.x.c.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
}
示例12: testDsNodataFromWildcardNsecCovered
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testDsNodataFromWildcardNsecCovered() throws IOException {
Message m = Message.newQuery(Record.newRecord(Name.fromString("www.x.ce.ingotronic.ch."), Type.A, DClass.IN));
m.addRecord(new ARecord(Name.fromString("www.x.ce.ingotronic.ch."), DClass.IN, 300, InetAddress.getLocalHost()), Section.ANSWER);
add("www.x.ce.ingotronic.ch./A", m);
Message response = resolver.send(createMessage("www.x.ce.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
}
示例13: testSmessageReturnsOptRecordOfOriginal
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testSmessageReturnsOptRecordOfOriginal() {
int xrcode = 0xFED;
Message m = Message.newQuery(Record.newRecord(Name.root, Type.NS, DClass.IN));
m.getHeader().setRcode(xrcode & 0xF);
m.addRecord(new OPTRecord(1, xrcode >> 4, 1), Section.ADDITIONAL);
SMessage sm = new SMessage(m);
assertEquals(m.toString(), sm.getMessage().toString());
assertEquals(xrcode, sm.getRcode());
}
示例14: testBlockedDnsQuery
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testBlockedDnsQuery() throws Exception {
Message message = Message.newQuery(new ARecord(new Name("blocked.example.com."),
0x01,
3600,
Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
));
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNotNull(mockEventLoop.lastResponse);
assertNull(mockEventLoop.lastOutgoing);
assertTrue(mockEventLoop.lastResponse instanceof IpPacket);
assertTrue(mockEventLoop.lastResponse.getPayload() instanceof UdpPacket);
Message responseMsg = new Message(mockEventLoop.lastResponse.getPayload().getPayload().getRawData());
assertEquals(NOERROR, responseMsg.getHeader().getRcode());
assertArrayEquals(new Record[] {}, responseMsg.getSectionArray(Section.ANSWER));
assertNotEquals(0, responseMsg.getSectionArray(Section.AUTHORITY).length);
assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0] instanceof SOARecord);
assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0].getTTL() > 0);
}
示例15: testBlockedInet6DnsQuery
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testBlockedInet6DnsQuery() throws Exception {
Message message = Message.newQuery(new ARecord(new Name("blocked.example.com."),
0x01,
3600,
Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
));
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr((Inet6Address) Inet6Address.getByName("::0"))
.dstAddr((Inet6Address) Inet6Address.getByName("::1"))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV6Packet.Builder()
.version(IpVersion.IPV6)
.trafficClass(IpV6SimpleTrafficClass.newInstance((byte) 0))
.flowLabel(IpV6SimpleFlowLabel.newInstance(0))
.nextHeader(IpNumber.UDP)
.srcAddr((Inet6Address) Inet6Address.getByName("::0"))
.dstAddr((Inet6Address) Inet6Address.getByName("::1"))
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNotNull(mockEventLoop.lastResponse);
assertNull(mockEventLoop.lastOutgoing);
assertTrue(mockEventLoop.lastResponse instanceof IpPacket);
assertTrue(mockEventLoop.lastResponse.getPayload() instanceof UdpPacket);
Message responseMsg = new Message(mockEventLoop.lastResponse.getPayload().getPayload().getRawData());
assertEquals(NOERROR, responseMsg.getHeader().getRcode());
assertArrayEquals(new Record[] {}, responseMsg.getSectionArray(Section.ANSWER));
assertNotEquals(0, responseMsg.getSectionArray(Section.AUTHORITY).length);
assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0] instanceof SOARecord);
assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0].getTTL() > 0);
}