<?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>Dogma &#187; backslash</title>
	<atom:link href="http://dogma.swiftspirit.co.za/archives/tag/backslash/feed" rel="self" type="application/rss+xml" />
	<link>http://dogma.swiftspirit.co.za</link>
	<description>... brakes for Pretty Rocks</description>
	<lastBuildDate>Thu, 10 Jun 2010 23:05:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Clearing DNS cache &#8211; regex part 2</title>
		<link>http://dogma.swiftspirit.co.za/archives/300</link>
		<comments>http://dogma.swiftspirit.co.za/archives/300#comments</comments>
		<pubDate>Sun, 26 Apr 2009 16:29:09 +0000</pubDate>
		<dc:creator>Tricky</dc:creator>
				<category><![CDATA[networking]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[about:config]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[backslash]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[clear private data]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[dns cache]]></category>
		<category><![CDATA[dnsmasq]]></category>
		<category><![CDATA[dscacheutil]]></category>
		<category><![CDATA[escape]]></category>
		<category><![CDATA[firefox dns flusher]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[intranet]]></category>
		<category><![CDATA[ip address]]></category>
		<category><![CDATA[ipconfig]]></category>
		<category><![CDATA[lookupd]]></category>
		<category><![CDATA[mac os x]]></category>
		<category><![CDATA[mozilla firefox]]></category>
		<category><![CDATA[netbsd]]></category>
		<category><![CDATA[nextstep]]></category>
		<category><![CDATA[nscd]]></category>
		<category><![CDATA[openbsd]]></category>
		<category><![CDATA[parentheses]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[private ip]]></category>
		<category><![CDATA[propagation]]></category>
		<category><![CDATA[public ip]]></category>
		<category><![CDATA[red hat]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[rndc]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[ttl]]></category>
		<category><![CDATA[vertical bar]]></category>
		<category><![CDATA[vpn]]></category>

		<guid isPermaLink="false">http://dogma.swiftspirit.co.za/?p=300</guid>
		<description><![CDATA[Trust me. We&#8217;re still dealing with regexes &#8211; just in a roundabout (and vaguely practical) way. This is a pretty comprehensive listing of how to go about flushing DNS caches while using regexes to show where similar methods deviate.
Why do we want to clear DNS caches exactly?
There are a number of reasons to clear DNS [...]]]></description>
			<content:encoded><![CDATA[<p>Trust me. We&#8217;re still dealing with regexes &#8211; just in a roundabout (and vaguely practical) way. This is a pretty comprehensive listing of how to go about flushing DNS caches while using regexes to show where similar methods deviate.</p>
<h3>Why do we want to clear DNS caches exactly?</h3>
<p>There are a number of reasons to clear <a href="http://www.dns.net/dnsrd/docs/whatis.html">DNS</a> <a href="http://en.wikipedia.org/wiki/Cache">caches</a>, though I believe these are the most common:</p>
<ul>
<li>An <a href="http://www.webopedia.com/TERM/I/intranet.html">intranet</a> service has an <a href="http://www.faqs.org/rfcs/rfc1918.html">priv</a><a href="http://www.rfc-editor.org/rfc/rfc4193.txt">ate</a> (internal) IP address when on the company network but it has a public IP address for outside access. When you try to access that service from outside after accessing it from inside, there&#8217;s a chance that you would have cached the private (inaccessible) IP. A good long-term solution is to make the service inaccessible except via <a href="http://computer.howstuffworks.com/vpn.htm">VPN</a>. A simpler solution is to leave work at work. <img src='http://dogma.swiftspirit.co.za/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </li>
<li>An internet service or web site changes their DNS settings and your desktop/laptop is looking at the &#8220;old&#8221; setting. In this case, the new setting has not yet <a href="http://www.lytebyte.com/2007/03/23/dns-propagation-and-the-reasons-for-its-delay/">propagated</a>. Hosting Admins come across this case  very often.</li>
<li>Privacy: If someone can track your DNS history then it wouldn&#8217;t be too hard to figure out which web sites you&#8217;ve been viewing. Though the individual pages you&#8217;ve viewed can&#8217;t be tracked in this way, the hostnames, such as &#8220;dogma.swiftspirit.co.za&#8221; or &#8220;google.com&#8221; will be in the DNS cache, likely in the order you first accessed each site. There are better ways to do this though. One example is to use a Tor network for all DNS requests.</li>
</ul>
<h3>Flushing Windows&#8217; DNS cache, from command prompt:</h3>
<p>Evidence suggests that prior to <a href="http://www.microsoft.com/windows2000/">Windows 2000</a>, <a href="http://www.microsoft.com/windows/">Windows</a> OS&#8217;s didn&#8217;t cache DNS results. The <a href="http://support.microsoft.com/kb/314850">ipconfig</a> command, run from the command prompt, was given some control over the DNS cache and has remained roughly the same since.</p>
<p>To get to the prompt if using <a href="http://www.microsoft.com/windows/windows-vista/">Vista</a> as non-Admin: Start -&gt; Programs -&gt; Accessories -&gt; Right-click &#8220;Command Prompt&#8221; -&gt; Run As Administrator</p>
<p>Otherwise: Start -&gt; <span style="text-decoration: underline;">R</span>un -&gt; [cmd         ] -&gt; [ OK ]</p>
<pre lang="">ipconfig /flushdns</pre>
<p style="text-align: center;"><a href="http://dogma.swiftspirit.co.za/wp-content/uploads/2009/03/flushdnswin0.png"><img class="size-full wp-image-341 aligncenter" title="Flush the DNS Resolver Cache in Windows" src="http://dogma.swiftspirit.co.za/wp-content/uploads/2009/03/flushdnswin0.png" alt="Flush the DNS Resolver Cache in Windows" width="466" height="146" /></a></p>
<p>It is also possible to clear the cache in Windows by <a href="http://technet.microsoft.com/en-us/library/cc736564.aspx">restarting</a> the &#8220;DNS Client&#8221; or &#8220;Dnscache&#8221; service.</p>
<h3>Flushing Mac OS X DNS cache, from shell prompt:</h3>
<p>Since <a href="http://www.apple.com/macosx/">Mac OS X</a>, Apple <a href="http://www.apple.com/mac/">Mac</a>s have been running a Unix-based, <a href="http://en.wikipedia.org/wiki/POSIX">POSIX</a>-compliant, operating system based on <a href="http://en.wikipedia.org/wiki/NeXTSTEP">Nextstep</a>, itself originally containing code from <a href="http://www.freebsd.org/">FreeBSD</a> and <a href="http://www.netbsd.org/">NetBSD</a>. Mac OS X uses <a href="http://support.apple.com/kb/TA25216?viewlocale=en_US">lookupd</a> or <a href="http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man1/dscacheutil.1.html">dscacheutil</a> to manage the DNS cache, depending on the version.</p>
<p>To get to the prompt: Applications -&gt; Utilities -&gt; Terminal</p>
<pre lang="" escaped="true">(lookupd|dscacheutil) -flushcache</pre>
<p>What have we here? As per <a href="http://dogma.swiftspirit.co.za/archives/371">part 1</a>, the <em>vertical bar</em> indicates that either &#8220;lookupd&#8221; <strong>OR</strong> &#8220;dscacheutil&#8221; are acceptable. The <em>parenthesis</em> indicate that the <em>vertical bar</em> only applies to the &#8220;lookupd|dscacheutil&#8221; portion of the expression. Thus, the &#8220; -flushcache&#8221; is not optional and must be included in the command in order for it to work. Note that these commands produce no output unless there is an error.</p>
<p>Use dscacheutil if you&#8217;re using Mac OS X 10.5 (Leopard) or later.</p>
<h4>Mac OS X:</h4>
<pre lang="">lookupd -flushcache</pre>
<h4>Mac OS X Leopard:</h4>
<pre lang="">dscacheutil -flushcache</pre>
<p><img class="aligncenter size-full wp-image-485" title="dscacheutil" src="http://dogma.swiftspirit.co.za/wp-content/uploads/2009/04/dscacheutil.png" alt="Use dscacheutil to flush the cache in Mac OS X Leopard" width="184" height="60" /></p>
<p>There is also a GUI tool, <a href="http://www.apple.com/downloads/macosx/networking_security/dnsflusher.html">DNS Flusher</a>, which automatically uses the correct command available.</p>
<h3>Flushing Linux/Unix&#8217; DNS cache, from shell prompt:</h3>
<p><strong>N.B.</strong> If you don&#8217;t already have either <acronym title="Berkeley Internet Name Domain">bind</acronym> (with caching lookup enabled), <acronym title="Name Server Caching Daemon">nscd</acronym>, or dnsmasq installed and running on your *nix-based desktop/server, you are probably <strong>not caching DNS at all</strong> and there is nothing to flush. In that case you will be utilising your DNS server for every web request, probably slowing your web experience.* If so, I recommend at least installing nscd as it is the easiest to set up. **</p>
<h4>Flushing nscd&#8217;s cache</h4>
<p>As with the Mac OS command, this produces absolutely no output unless there is an error:</p>
<pre lang="">(|sudo )(|/usr/sbin/)nscd -i hosts</pre>
<ul>
<li>Use <a href="http://www.gratisoft.us/sudo/">sudo</a> if you&#8217;re not already <a href="http://knowledgerush.com/kr/encyclopedia/Root_(computing)/">root</a> otherwise the first selection is blank.</li>
<li>Specify /usr/sbin/ if nscd is not already within the &#8220;path&#8221;. If your distribution has nscd in a strange place, locate it first:</li>
</ul>
<pre lang="">locate -r bin/nscd$</pre>
<p><em>Notice that the above &#8220;bin/nscd$&#8221; is itself a regular expression. <img src='http://dogma.swiftspirit.co.za/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<h5>Using nscd, invalidate the &#8220;hosts&#8221; cache, logged in as a user:</h5>
<pre lang="">sudo nscd -i hosts</pre>
<h5>Using nscd, invalidate the &#8220;hosts&#8221; cache, logged in as root:</h5>
<pre lang="">nscd -i hosts</pre>
<h5>Using nscd, invalidate the &#8220;hosts&#8221; cache, logged in as root, specifying the full path:</h5>
<pre lang="">/usr/sbin/nscd -i hosts</pre>
<h4>Flushing bind&#8217;s cache</h4>
<p>To flush bind&#8217;s cache, we issue a command via <acronym title="remote name daemon control">rndc</acronym>. Use sudo if you are not already root:</p>
<pre lang="">(|sudo )rndc flush</pre>
<h3>Restarting the cacheing services also works!</h3>
<p>Here&#8217;s how to restart either of the caching daemons:</p>
<pre lang="">(|sudo )(service |/etc/(rc\.d|rc\.d/init\.d|init\.d)/)(bind|dnsmasq|nscd) restart</pre>
<p>That&#8217;s starting to get difficult to read. *** Luckily I&#8217;ve explained in detail:</p>
<ul>
<li>As with the previous command, use sudo if you&#8217;re not already root.</li>
<li>The second selection has the first option &#8220;service &#8220;. This applies mainly to Red Hat/CentOS and Fedora systems.</li>
<li>The &#8220;/etc/(rc\.d|rc\.d/init\.d|init\.d)/&#8221; needs to be expanded further. This is for most other systems. Generally, the rc.d is for if you&#8217;re using a BSD-style init system (for example: Arch Linux, FreeBSD, or OpenBSD). The best way to know for sure which command to use is to &#8216;locate&#8217; the correct nscd or <a href="http://thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a> path. Most Unix flavours, even Solaris, use nscd:</li>
</ul>
<pre lang="">locate -r \.d/nscd$ ; locate -r \.d/dnsmasq$ ; locate -r \.d/rndc$</pre>
<ul>
<li>The last choice is between &#8220;bind&#8221;, &#8220;nscd&#8221;, and &#8220;dnsmasq&#8221;. This depends entirely on which is installed and in use.</li>
<li>The last of the pattern, &#8221; restart&#8221;, is the instruction given to the daemon&#8217;s control script.</li>
</ul>
<h4>Arch, using dnsmasq, restarting the cache daemon, logged in as root:</h4>
<pre lang="">/etc/rc.d/dnsmasq restart</pre>
<h4>Arch, using nscd, restarting the cache daemon, logged in as user:</h4>
<pre lang="">sudo /etc/rc.d/nscd restart</pre>
<h4>CentOS / Red Hat, using nscd, restarting the daemon, as root:</h4>
<pre lang="">service nscd restart</pre>
<p><img class="aligncenter size-full wp-image-483" title="Restart nscd to flush the cache" src="http://dogma.swiftspirit.co.za/wp-content/uploads/2009/04/nscdrestart1.png" alt="nscdrestart" width="535" height="73" /></p>
<h3>Flush Mozilla Firefox&#8217;s internal DNS cache:</h3>
<p><a href="http://www.mozilla.com/firefox/">Mozilla Firefox</a> keeps its own DNS cache for performance. Firefox 2 would cache only 20 entries for up to 60 seconds. The default setting as of Firefox 3 appears to be 512 entries for up to 60 minutes which seems much more reasonable for every-day browsing. If your desktop has a built-in cache (which most now do) then the cache here is actually redundant. I&#8217;m not aware of any other browsers that implement DNS caching.</p>
<p>I&#8217;ve found a few solutions for when you need to clear the cache. It seems there are many ways to do this however these are the easiest, which I&#8217;ve put into order of preference.:</p>
<ol>
<li>Install the <a href="https://addons.mozilla.org/en-US/firefox/addon/7408">Firefox DNS Flusher</a> Addon &#8211; provides a button to flush the cache.</li>
<li>Install the <a href="https://addons.mozilla.org/en-US/firefox/addon/5914">DNS Cache</a> Addon &#8211; provides a toggle which disables or enables the DNS cache.</li>
<li>Clear Cache (clears browser cache as well as DNS Cache): Select <span style="text-decoration: underline;">T</span>ools -&gt; Clear <span style="text-decoration: underline;">P</span>rivate Data; Deselect all checkboxes except for C<span style="text-decoration: underline;">a</span>che; Click [ Clear Private Data Now ].</li>
<li>Manually do what DNS Cache does: set the following 2 <a href="http://kb.mozillazine.org/About:config">about:config</a> options &#8220;network.dnsCacheExpiration&#8221; and &#8220;network.dnsCacheEntries&#8221; to 0 and then back to the default.</li>
</ol>
<h3>I had a bad cached record and I cleared my browser&#8217;s cache. But its still giving me the wrong info. What gives?</h3>
<p>Because of how DNS propagation works, you preferably need to flush the DNS on <strong>all</strong> DNS hosts between yourself and the &#8220;authoritive&#8221; host, starting with the host closest to the authoritive host (furthest away from your browser).</p>
<p>As an example, if you have a router that is caching DNS, reset the router&#8217;s cache before restarting the DNS cache of your operating system, and only <strong>then</strong> should you clear the cache in Firefox. The reason is that even if you only clear your OS and Firefox&#8217;s caches, your desktop is still going to ask the router for its <strong>bad</strong> record anyway.</p>
<h3>What if my DNS server is a server on the net outside my control?</h3>
<p>You could try temporarily using a different nameserver, possibly even a publicly <a href="https://www.opendns.com/start/">open</a> server. OpenDNS shows some good information on how to do this. If you&#8217;d like, you should also be able to get relevant information from your own ISP regarding their resolving DNS servers. A local example (South Africa) is <acronym title="South African Internet Exchange">SAIX</acronym> which <a href="http://www.saix.net/cgi-bin/saix_dns.pl">lists</a> their resolving DNS servers.</p>
<address>* Likely the reason why Firefox has a DNS cache built-in ****</address>
<address>** &#8220;((pacman|yaourt) -S|emerge|(yum|aptitude|apt-get) install) nscd&#8221; and then ensure that the service is added to the startup scripts. Refer to your distribution&#8217;s installation documentation. </address>
<address>*** I&#8217;m looking for a syntax highlighting plugin that can work with regex<br />
</address>
<address>**** I&#8217;ve read statements that restarting the network(ing|) service also clears the DNS cache however I haven&#8217;t seen any evidence that this is true. If anyone has a example where this is true, please provide me with the details.</address>
]]></content:encoded>
			<wfw:commentRss>http://dogma.swiftspirit.co.za/archives/300/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Regex part 1 &#8211; matching patterns</title>
		<link>http://dogma.swiftspirit.co.za/archives/371</link>
		<comments>http://dogma.swiftspirit.co.za/archives/371#comments</comments>
		<pubDate>Mon, 06 Apr 2009 01:03:22 +0000</pubDate>
		<dc:creator>Tricky</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[address]]></category>
		<category><![CDATA[backslash]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[escape]]></category>
		<category><![CDATA[match]]></category>
		<category><![CDATA[order of operations]]></category>
		<category><![CDATA[parentheses]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[uri]]></category>
		<category><![CDATA[vertical bar]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://dogma.swiftspirit.co.za/?p=371</guid>
		<description><![CDATA[A colleague is looking to learn regex so I decided to put it up here. This is the first in a series of regex-related articles. In the parts to follow, we&#8217;re going to be using our Regular Expressions to learn other topics relevant to the Internet while simltaneously expanding on regex knowledge.
Regex Quick Start

A vertical [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague is looking to learn <abbr title="regular expressions">regex</abbr> so I decided to put it up here. This is the first in a series of regex-related articles. In the parts to follow, we&#8217;re going to be using our <a href="http://www.google.com/search?q=define%3Aregular+expressions">Regular Expressions</a> to learn other topics relevant to the Internet while simltaneously expanding on regex knowledge.</p>
<h3>Regex Quick Start</h3>
<ol>
<li>A <a href="http://www.answers.com/topic/vertical-bar">vertical bar</a> |, sometimes known as a pipe, is an &#8220;OR&#8221; operator in regular expressions. It indicates that the pattern to the left OR to the right is acceptable. On the keyboard, this key is typically the &#8220;capital&#8221;, or &#8220;shifted version&#8221;, of the backslash key.</li>
<li>Parentheses are round brackets () that select a section of a regular expression. They can be used similarly to in mathematics when the <a href="http://en.wikipedia.org/wiki/Order_of_operations">order of operations</a> is adjusted. The &#8220;selection&#8221; can be referenced elsewhere though we&#8217;ll cover that later.</li>
<li>A <a href="http://www.regular-expressions.info/dot.html">dot .</a> is a special character which matches <em>any</em> character other than &#8220;newline&#8221; characters.</li>
<li>A backslash \ is sometimes called an <a href="http://en.wikipedia.org/wiki/Escape_character">escape</a> character. There are many characters, such as the parentheses and the vertical bar above, that have special meanings. The backslash is used to take away (escape) those special meanings. For example, to specify an actual full stop, you need to escape the special dot character: \.</li>
<li>A star * is an operator which indicates that the preceding character can be repeated zero or more times. This is often combined with the dot to produce a &#8220;wildcard&#8221; pattern, which matches a string of any length: .*</li>
</ol>
<h3>Using the vertical bar and the escape character</h3>
<p>Here we have a number of example web addresses:</p>
<pre style="padding-left: 30px;">http://dogma.swiftspirit.co.za/

http://swiftspirit.co.za/

http://google.com/</pre>
<p>If I want a pattern that matches them all, I could use the vertical bar (rule 1 above) to separate them. I&#8217;d then also need to use the escape character (rule 4 above) for the full stops:</p>
<pre style="padding-left: 30px;">http://dogma\.swiftspirit\.co\.za/|http://swiftspirit\.co\.za|http://google\.com/</pre>
<p>To above will match every URI in my example however it isn&#8217;t specifically efficient or elegant.</p>
<h3>Using parenthesis</h3>
<p>The same can be achieved with the following, shorter, regex, utilising the parenthesis from rule 2 above:</p>
<pre style="padding-left: 30px;">http://((|dogma\.)swiftspirit\.co\.za|google\.com)/</pre>
<p>Notice that I&#8217;ve simply placed common items, for example &#8220;http://&#8221; and &#8220;/&#8221;, outside the selections.</p>
<h3>What if you want to match text that might be anything?</h3>
<p>Maybe you have more that you still want to match? For example, if I put <a href="http://swiftspirit.co.za/downloads/">http://swiftspirit.co.za/downloads/</a> and I still want the pattern to match that or any other url under my web site. Or maybe its okay for http://<em>anything</em>.google.com/<em>anything</em> to also match. We can use the special dot and star characters from rules 3 and 5 from above:</p>
<pre style="padding-left: 30px;">http://((|dogma\.)swiftspirit\.co\.za|(|.*\.)google\.com)/.*</pre>
<p>Simply adding that any character can appear zero or more times lets a lot more match without adding too much to the regex&#8217;s complexity:</p>
<pre style="padding-left: 30px;">(|.*\.)</pre>
<p>The above is from in front of the google.com pattern. The vertical bar indicates two options here: either blank (so we end up with just google.com), or <strong>.*\.</strong> (so we have <em>anything</em> followed by a literal dot and that is then followed by google.com).</p>
<h3>Practise makes perfect</h3>
<p>We can already see from the last example that a regular expression can very quickly become complex. Much like any language, being easily able to read a regular expression takes practice. If you have a relevant need to work with regular expressions, you&#8217;re in for a treat.</p>
<p>Part 2 should be due in a few days. I&#8217;ll be doing some very indirect &#8220;work&#8221;, demonstrating how to flush DNS caches in a variety of systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://dogma.swiftspirit.co.za/archives/371/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
