<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>哇寶部落格 &#187; cname</title>
	<atom:link href="http://blog.wabow.com/archives/tag/cname/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.wabow.com</link>
	<description>Wabow Information Inc. Blog</description>
	<lastBuildDate>Fri, 21 May 2010 15:11:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>用 PHP 查 DOMAIN 的 CNAME 紀錄</title>
		<link>http://blog.wabow.com/archives/2066</link>
		<comments>http://blog.wabow.com/archives/2066#comments</comments>
		<pubDate>Thu, 27 Aug 2009 06:44:34 +0000</pubDate>
		<dc:creator>suzy</dc:creator>
				<category><![CDATA[軟體測試]]></category>
		<category><![CDATA[cname]]></category>

		<guid isPermaLink="false">http://blog.wabow.com/?p=2066</guid>
		<description><![CDATA[接獲一項來自 Neo 的任務, "用PHP 實作由 CNAME 去判定新加入服務的 DOMAIN 為申請人所有" (證明他不是來亂的). For Example: Google Apps 就是用這個方式去作驗證 CNAME 是 DOMAIN or SUB DOMAIN 指向另一個 DOMAIN 的方式. (跟 alias 一樣) 那麼如果要用 PHP 實作呢? 有兩種方式 : 1. PHP5 內建的 dns_get_record() (Windows &#38; BSD &#38; Mac 不適用) 2. PEAR NET_DNS NET_DNS 原理是用 fsockopen("你的 DNS SERVER IP", 53), 但是要先自己組合出 "封包的header data" [...]]]></description>
			<content:encoded><![CDATA[<p>接獲一項來自 Neo 的任務, "用PHP 實作由 CNAME 去判定新加入服務的 DOMAIN 為申請人所有" (證明他不是來亂的).</p>
<p>For Example:<br />
<a href="http://www.google.com/support/a/bin/answer.py?hl=b5&amp;answer=92354">Google Apps 就是用這個方式去作驗證</a><br />
<span id="more-2066"></span></p>
<p><a href="http://www.google.com.tw/search?hl=zh-TW&amp;q=CNAME">CNAME</a> 是 DOMAIN or SUB DOMAIN 指向另一個 DOMAIN 的方式. (跟 alias 一樣)</p>
<p>那麼如果要用 PHP 實作呢? 有兩種方式 :<br />
1. PHP5 內建的 dns_get_record() (Windows &amp; BSD &amp; Mac 不適用)<br />
2. PEAR <a href="http://pear.php.net/package/Net_DNS">NET_DNS</a></p>
<p>NET_DNS 原理是用 fsockopen("你的 DNS SERVER IP", 53),<br />
但是要先自己組合出 "封包的header data" 再丟過去, DNS Server 才會理你唷.<br />
這些複雜的部份 NET_DNS 已經都幫我們做好了.</p>
<p>我們只要:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Net/DNS.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ndr</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Net_DNS_Resolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ndr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;www.OOO.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;CNAME&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;pre&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$answer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 獲得的結果</span>
<span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Net_DNS_RR_CNAME Object
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> www<span style="color: #339933;">.</span>OOO<span style="color: #339933;">.</span>co<span style="color: #339933;">.</span>nz
            <span style="color: #009900;">&#91;</span>type<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> CNAME
            <span style="color: #009900;">&#91;</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> IN
            <span style="color: #009900;">&#91;</span>ttl<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">86400</span>
            <span style="color: #009900;">&#91;</span>rdlength<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">18</span>
            <span style="color: #009900;">&#91;</span>rdata<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> store	XXX�<span style="color: #cc66cc;">3</span>
            <span style="color: #009900;">&#91;</span>cname<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> store<span style="color: #339933;">.</span>XXX<span style="color: #339933;">.</span>com
        <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>PS, 在 Windows 環境, 請修改 PEAR/NET/DNS/Resolver.php 裡的</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$resolv_conf</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/etc/resolv.conf'</span><span style="color: #339933;">;</span></pre></div></div>

<p>改成</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$resolv_conf</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'D:\Appserv\resolv.conf'</span><span style="color: #339933;">;</span></pre></div></div>

<p>resolv.conf 要加入你的 DNS Server (請用 ipconfig /all 查詢)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">nameserver 168<span style="color: #339933;">.</span>95<span style="color: #339933;">.</span>192<span style="color: #339933;">.</span>1</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.wabow.com/archives/2066/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
