AIR 2.0 offers an API flash.net.dns.DNSResolver that allows the making of queries to find out Domain name system (DNS) information. Once information has been found, a DNSResolverEvent is dispatched. Need an application that shows how to use the new API.
Take a look at the app example, which performs DNS and reverse DNS lookup.
AIR 2.0 offers an API flash.net.dns.DNSResolver that allows the making of queries to find out Domain name system (DNS) information. Once information has been found, a DNSResolverEvent is dispatched.
To understand how to use the new API you must first understand what DNS is and how it works. Each domain name on the web is pointing to an IP address. DNS converts domain names into IP addresses. In other words, the DNS allows the translation of the information from host name into IP addresses.
The IP address can be of type IPv4 (32-bits) or IPv6 (64-bits). AIR 1.0 supported IPv4, and all the classes in AIR 2.0 now support the IPv6 protocol. There are many record types that are stored in the resource records on DNS, and they include the IPv4 address record, the IPv6 address record, delegation name, DNS key records, and many others.
In this release AIR only supports the following DNS types:
· flash.net.dns.ARecord - Class that returns 64-bits IPv6 address information. AAAA (AAAA stands for a resource records code) records are usually used to convert hostnames into IP addresses. flash.net.dns.AAAARecord - Same as ARecord but used to return a 32-bits IPv4 address.
· flash.net.dns.MXRecord - Class that provides information regarding mapping a domain name to a list of mail exchange (MX) servers for that domain.
· flash.net.dns.SRVRecord - SRV class that returns service location record information about the SRV records. It is used for newer protocols instead of creating protocol-specific records such as MX.
· flash.net.dns.ResourceRecord - Data class for encapsulating the information in a DNS record.
· flash.net.dns.PTRRecord - Class to allow accessing PTR record information. PTR record is usually used for performing reverse DNS lookups.
<?xml version="1.0"
encoding="utf-8"?>
<s:WindowedApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
height="287"
width="505">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.net.dns.SRVRecord;
import flash.net.dns.PTRRecord;
import flash.net.dns.MXRecord;
import flash.net.dns.ARecord;
import flash.events.Event;
import flash.net.dns.AAAARecord;
import flash.events.DNSResolverEvent;
import flash.net.dns.DNSResolver;
private var resolver:DNSResolver;
public function startLookup( host:String,
isARecordSelected:Boolean, isAAAARecordSelected:Boolean,
isMXRecordSelected:Boolean, isSRVRecordSelected:Boolean ):void
{
if (isARecordSelected) lookup( host + ".",
ARecord );
if (isAAAARecordSelected) lookup( host,
AAAARecord );
if (isMXRecordSelected) lookup( host, MXRecord
);
if (isSRVRecordSelected) lookup( "_sip._tcp." +
host + ".", SRVRecord );
}
public function lookup( host:String, recordType:Class):void
{
resolver = new DNSResolver();
resolver.addEventListener(
DNSResolverEvent.LOOKUP, lookupComplete );
resolver.addEventListener( ErrorEvent.ERROR,
lookupError );
resolver.lookup( host, recordType );
}
private function lookupComplete( event:DNSResolverEvent ):void
{
resolver.removeEventListener(
DNSResolverEvent.LOOKUP, lookupComplete );
resolver.removeEventListener( ErrorEvent.ERROR,
lookupError );
setOutput( "Query string: " + event.host );
setOutput( "Record type: " +
flash.utils.getQualifiedClassName( event.resourceRecords[0] ) +
", count: " +
event.resourceRecords.length );
for each( var record:* in event.resourceRecords
)
{
if( record is ARecord )
setOutput( "ARecord: " + record.name + " : " + record.address );
if( record is AAAARecord )
setOutput( "AAAARecord: " + record.name + " : " + record.address );
if( record is MXRecord )
setOutput( "MXRecord: " + record.name + " : " + record.exchange +
", " + record.preference );
if( record is PTRRecord )
setOutput( "PTRRecord: " + record.name + " : " + record.ptrdName );
if( record is SRVRecord )
setOutput( "SRVRecord: " + record.name + " : " + record.target + ",
" + record.port +
", " +
record.priority + ", " + record.weight );
}
}
private function setOutput(message:String):void
{
resolver.removeEventListener(
DNSResolverEvent.LOOKUP, lookupComplete );
resolver.removeEventListener( ErrorEvent.ERROR,
lookupError );
output.text = message + "\n" + output.text;
}
private function lookupError( error:ErrorEvent ):void
{
Alert.show("Error: " + error.text );
}
]]>
</fx:Script>
<s:TextInput id="DomainTextInput"
x="129" y="55" text="yahoo.com"/>
<s:Button x="330" y="55" label="Lookup
DNS Information"
click="startLookup(DomainTextInput.text,
checkBoxARecord.selected, checkBoxAAAARecord.selected,
checkBoxMXRecord.selected,
checkBoxSRVRecord.selected)"/>
<s:CheckBox id="checkBoxARecord" x="28"
y="85" label="ARecord" selected="true"/>
<s:CheckBox id="checkBoxAAAARecord"
x="101" y="85" label="AAAARecord"/>
<s:CheckBox id="checkBoxMXRecord"
x="196" y="85" label="MXRecord"/>
<s:CheckBox id="checkBoxSRVRecord"
x="276" y="85" label="SRVRecord"/>
<s:TextInput id="ipAddress" x="129"
y="120"/>
<s:Button x="330" y="120"
label="Reverse DNS Lookup" width="152"
click="lookup(ipAddress.text, PTRRecord )"/>
<s:Label x="28" y="21" text="DNS
Lookup:"
fontSize="21"/>
<s:TextArea id="output" x="28" y="158"
width="454" height="104" text=""/>
<s:RichText x="28" y="58" text="Host
name: " height="15" fontSize="16"/>
<s:RichText x="28" y="123" text="IP
Address:" height="15" fontSize="16"/>
</s:WindowedApplication>
To learn more about this feature and more order AdvancED Flex 4
+