<?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>project-2501.net</title>
	<atom:link href="http://project-2501.net/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://project-2501.net</link>
	<description>The net is vast and infinite.</description>
	<lastBuildDate>Tue, 08 Nov 2011 10:38:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Post-Increment Variable Bug</title>
		<link>http://project-2501.net/index.php/2011/11/post-increment-variable-bug/</link>
		<comments>http://project-2501.net/index.php/2011/11/post-increment-variable-bug/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 10:38:06 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=404</guid>
		<description><![CDATA[Found this little bug today in some old (untested code). I was amused that the code would have worked using pre-increment operator (and yet, still been wrong). # Simplified example, in the original code this was 3 lines long # Assume use_record_map = false; record_id = &#40;use_record_map&#41; ? lookup_record_id&#40;foo&#41; : record_id++; Pythons lack of ++ [...]]]></description>
			<content:encoded><![CDATA[<p>Found this little bug today in some old (untested code).  I was amused that the code would have worked using pre-increment operator (and yet, still been wrong).</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># Simplified example, in the original code this was 3 lines long</span><br />
<span style="color: #808080; font-style: italic;"># Assume use_record_map = false;</span><br />
record_id <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span>use_record_map<span style="color: black;">&#41;</span> ? lookup_record_id<span style="color: black;">&#40;</span>foo<span style="color: black;">&#41;</span> : record_id++<span style="color: #66cc66;">;</span></div></div>
<p>Pythons lack of ++ / &#8212; operators makes a little more sense now (one extra character in exchange for removing several type of bugs.  Even if they are rather obvious bugs).</p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/11/post-increment-variable-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Car :)</title>
		<link>http://project-2501.net/index.php/2011/10/new-car/</link>
		<comments>http://project-2501.net/index.php/2011/10/new-car/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 11:27:21 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=405</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://project-2501.net/gallery/other/falcon-xt.jpeg"><img src="http://project-2501.net/gallery/.thumbs/gallery_other_falcon-xt.jpeg.jpeg"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/10/new-car/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Guild Wars: E/Me Vaettir Farm</title>
		<link>http://project-2501.net/index.php/2011/10/guild-wars-eme-vaettir-farm/</link>
		<comments>http://project-2501.net/index.php/2011/10/guild-wars-eme-vaettir-farm/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 03:14:28 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=397</guid>
		<description><![CDATA[E/Me Obsidian Flesh Vaettir Farm (HM) Skills OgVFI7QIlMPkLo0n2wXlBgMwSgWF Elemental Lord (Optional) Glyph of Swiftness Obsidian Flesh Stoneflesh Aura Mantra of Earth Wastrel&#8217;s Worry Arcane Echo Storm Djinn&#8217;s Haste (Optional) Attributes 12 + 3 + 1 Earth Magic 3 + 1 Energy Storage 4 Air Magic 4 Inspiration Magic 11 Domination Weapon +20% Enchantment length Armor [...]]]></description>
			<content:encoded><![CDATA[<p><object width="560" height="315"><param name="movie" value="http://www.youtube.com/v/ygLy1Ebh-7s?version=3&#038;feature=oembed"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ygLy1Ebh-7s?version=3&#038;feature=oembed" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<blockquote><p>
E/Me Obsidian Flesh Vaettir Farm (HM)</p>
<p><strong>Skills</strong></p>
<p>OgVFI7QIlMPkLo0n2wXlBgMwSgWF</p>
<p>Elemental Lord (Optional)<br />
Glyph of Swiftness<br />
Obsidian Flesh<br />
Stoneflesh Aura<br />
Mantra of Earth<br />
Wastrel&#8217;s Worry<br />
Arcane Echo<br />
Storm Djinn&#8217;s Haste (Optional)</p>
<p><strong>Attributes</strong></p>
<p>12 + 3 + 1 Earth Magic<br />
3 + 1 Energy Storage<br />
4 Air Magic<br />
4 Inspiration Magic<br />
11 Domination</p>
<p><strong>Weapon</strong></p>
<p>+20% Enchantment length</p>
<p><strong>Armor</strong></p>
<p>5x Geomancer Runes (I think you can get away with a +10 earth shield instead)<br />
Sup Earth Magic<br />
Minor Energy Storage</p>
<p><strong>Notes</strong></p>
<ul>
<li>If you get attacked by the Wurm in Bjora Marches, just put up Obsidian Flesh right away and you&#8217;ll be fine</li>
<li>When you have all 60 mobs drag them in between the building + wall to stop them scattering</li>
<li>Be careful not to let them body block you</li>
<li>Elemental Lord isn&#8217;t required, and only gives you an extra 1s on Obsidian flesh.</li>
<li>A faster, nicer A/Me run can be found here: <a href="http://www.youtube.com/watch?v=zZ1h2GoOpag">http://www.youtube.com/watch?v=zZ1h2GoOpag</a></li>
</ul>
<p>Recorded 2011-10-12
</p></blockquote>
<p>In other news, currently at <a href="http://hom.guildwars2.com/en/#page=main&#038;details=kMEAA8%2F%2F%2F%2FDAgQAAAgHAAAAAAAIAAAAAYGEQAAAAAAA&#038;todo=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA">29/50 points in the Hall of Monuments</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/10/guild-wars-eme-vaettir-farm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Guild Wars: Capturing a Black Widow spider</title>
		<link>http://project-2501.net/index.php/2011/09/guild-wars-capturing-a-black-widow-spider/</link>
		<comments>http://project-2501.net/index.php/2011/09/guild-wars-capturing-a-black-widow-spider/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 12:18:37 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=392</guid>
		<description><![CDATA[Some more random Fraps footage this time from Guild Wars. Been busy getting points in the Hall of Monuments. Nothing impressive, but I had never done much end-game content, and maybe it will help save someone else some gold after seeing how easy it is. I took 6 heros: Three Discordway Necros, Prot Monk, Panic [...]]]></description>
			<content:encoded><![CDATA[<p>Some more random Fraps footage this time from Guild Wars.  Been busy getting points in the <a href="http://hom.guildwars2.com/en/#page=main&#038;details=AIEAA8%2F%2F%2F%2FDAgQAAAgHAAAAAAAIAAAAAOGEQAAAAAAA&#038;todo=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA">Hall of Monuments.</a></p>
<p><object width="560" height="315"><param name="movie" value="http://www.youtube.com/v/fWgBXKqAp84?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/fWgBXKqAp84?version=3" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<blockquote>
<p>
Nothing impressive, but I had never done much end-game content, and maybe it will help save someone else some gold after seeing how easy it is.
</p>
<p>
I took 6 heros: Three Discordway Necros, Prot Monk, Panic Mesmer and a SoS Ritulist. Ump came with me on his Barrage Ranger, and I had some stupid Ele/R spec (with unspent points&#8230;).
</p>
<p>
The entire run took less than 30 minutes and I&#8217;m sure if you had a real build and knew where you were going, it would be very fast.
</p>
<p><strong>Walk-through:</strong></p>
<ul>
<li>Clear out the spawn area without accepting any quests</li>
<li>Take the Clear the Chamber quest from the spawn area and clear out the new mobs</li>
<li>Head north/west and take out all the mobs on the way</li>
<li>Talk to the Reaper of the Labyrinth and take the quest Restoring Grenth&#8217;s Monuments</li>
<li>Head south until you reach the Reaper of the Forgotten Vale </li>
<li>Clear out any nearby Coldfire Nights to the north</li>
<li>Take the quest Wrathful Spirits and kill all the Wrathful Spirits (Making sure not to let the Mayor die)</li>
<li>Hand in the quest and capture your spider (remember to flag the Heros well away from you, or they&#8217;ll kill the spider as you start to charm it)</li>
</ul>
<p>
Recorded 2011-09-20
</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/09/guild-wars-capturing-a-black-widow-spider/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Diablo 2 Fun</title>
		<link>http://project-2501.net/index.php/2011/08/diablo-2-fun/</link>
		<comments>http://project-2501.net/index.php/2011/08/diablo-2-fun/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 14:40:06 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=380</guid>
		<description><![CDATA[Just some fraps footage I had on my HDD taking up space I follow Umpa around as he kills Lilith, Uber Izual, Uber Duriel, Uber Mephisto, Uber Baal and finally Pandemonium Diablo. Recorded 2nd July 2011 US West Ladder My Character]]></description>
			<content:encoded><![CDATA[<p>Just some fraps footage I had on my HDD taking up space <img src='http://project-2501.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/N0xCwZpN45Q?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/N0xCwZpN45Q?version=3" type="application/x-shockwave-flash" width="560" height="340" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<blockquote><p>I follow Umpa around as he kills Lilith, Uber Izual, Uber Duriel, Uber Mephisto, Uber Baal and finally Pandemonium Diablo.</p>
<p>Recorded 2nd July 2011</p>
<p>US West Ladder</p>
<p><a href="http://project-2501.net/gallery/games/diablo2%20hammerdin%2020110827.png">My Character</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/08/diablo-2-fun/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Roman Numerals</title>
		<link>http://project-2501.net/index.php/2011/08/roman-numerals/</link>
		<comments>http://project-2501.net/index.php/2011/08/roman-numerals/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 10:00:13 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=363</guid>
		<description><![CDATA[From reddit.com/r/programingchallenges: I googled this and I haven&#8217;t found a similar challenge, so I&#8217;d like to pose this question to you all! Let&#8217;s say I give you a range from 1 to 2000. Within this range, find the number that yields the most characters. I asked a friend of mine and he worked out that [...]]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://www.reddit.com/r/programingchallenges/comments/i1m62/challenge_find_the_number_in_a_given_range_that/">reddit.com/r/programingchallenges</a>:</p>
<blockquote><p> I googled this and I haven&#8217;t found a similar challenge, so I&#8217;d like to pose this question to you all!<br />
Let&#8217;s say I give you a range from 1 to 2000. Within this range, find the number that yields the most characters. I asked a friend of mine and he worked out that 1888 has a lot of characters (MDCCCLXXXVIII).</p></blockquote>
<p><Strong>Solution</strong></p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span><br />
<br />
SYMBOLS <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'M'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'CM'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">900</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'D'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">500</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'CD'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">400</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'C'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'XC'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">90</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'L'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">50</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'XL'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">40</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'X'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'IX'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'V'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'IV'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'I'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> roman_numeral<span style="color: black;">&#40;</span>number<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; roman_number <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">symbol</span><span style="color: #66cc66;">,</span> value<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> SYMBOLS:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> value <span style="color: #66cc66;">&lt;=</span> number:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; roman_number.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">symbol</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; number -<span style="color: #66cc66;">=</span> value<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>roman_number<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<br />
<br />
start <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<br />
pairs <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>i<span style="color: #66cc66;">,</span> roman_numeral<span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">2000</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><br />
pairs.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> a<span style="color: #66cc66;">,</span>b: <span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>b<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Longest roman numeral for numbers 1-2000 = %d -&gt; %s'</span> % &nbsp;\<br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>pairs<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> pairs<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Took: %.2fsec'</span> % <span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - start<span style="color: #66cc66;">,</span><span style="color: black;">&#41;</span></div></div>
<p><strong>Output</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Longest roman numeral for numbers 1-2000 = 1888 -&gt; MDCCCLXXXVIII<br />
Took: 0.14sec</div></div>
<p><strong>Notes</strong><br />
Turns out historically there wasn&#8217;t a strict set of rules for Roman numerals, for example IV and IIII are both valid representations of the number 4.  Only recent rules have added limits on the number of repeated characters and what values can be subtracted from other values. <a href="http://en.wikipedia.org/wiki/Roman_numerals#Reading Roman numerals">Reference</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/08/roman-numerals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IP Address Range PHP Class</title>
		<link>http://project-2501.net/index.php/2011/07/ip-address-range-php-class/</link>
		<comments>http://project-2501.net/index.php/2011/07/ip-address-range-php-class/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 12:00:10 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=349</guid>
		<description><![CDATA[I&#8217;m not sure how useful this piece of code really is, but it gave me the chance to write some funky PHP code (have a look at the next() method). Example usage &#60;?php // Single host: foreach&#40;new IpRange&#40;'10.10.10.10'&#41; as $ip&#41; &#123; &#160; &#160; echo $ip . &#34;\n&#34; &#125; // &#62;&#62;&#62; 10.10.10.10 // All hosts on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure how useful this piece of code really is, but it gave me the chance to write some funky PHP code (have a look at the next() method).</p>
<h3>Example usage</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Single host:</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IpRange<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'10.10.10.10'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 10.10.10.10</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">// All hosts on a private network:</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IpRange<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'192.168.0.1-255'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.1</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.2</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; ...</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.254</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.255</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">// All normal (not broadcast, or multicast) IP addresses:</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IpRange<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1-232.0-255.0-255.0-255'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$k</span> =&gt; <span style="color: #006699; font-weight: bold;">$v</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 0 =&gt; 1.0.0.0</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 1 =&gt; 1.0.0.1</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 2 =&gt; 1.0.0.2</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; ...</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 7315795 =&gt; 1.111.161.83</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 7315796 =&gt; 1.111.161.84</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; etc</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<h3>Source</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
<br />
&nbsp; &nbsp; Copyright (c) 2011, Matthew Davey &lt;matthewd@project-2501.net&gt;<br />
&nbsp; &nbsp; All rights reserved.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Redistribution and use in source and binary forms, with or without<br />
&nbsp; &nbsp; modification, are permitted provided that the following conditions are met:<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; Redistributions of source code must retain the above copyright notice,<br />
&nbsp; &nbsp; &nbsp; &nbsp; this list of conditions and the following disclaimer.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; Redistributions in binary form must reproduce the above copyright<br />
&nbsp; &nbsp; &nbsp; &nbsp; notice, this list of conditions and the following disclaimer in the<br />
&nbsp; &nbsp; &nbsp; &nbsp; documentation and/or other materials provided with the distribution.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;<br />
&nbsp; &nbsp; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
&nbsp; &nbsp; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
&nbsp; &nbsp; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE<br />
&nbsp; &nbsp; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br />
&nbsp; &nbsp; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br />
&nbsp; &nbsp; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br />
&nbsp; &nbsp; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br />
&nbsp; &nbsp; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br />
&nbsp; &nbsp; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br />
&nbsp; &nbsp; POSSIBILITY OF SUCH DAMAGE.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; IpRange Class<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Given an IP address where each octet can either be a number between 0 and<br />
&nbsp; &nbsp; 255, or a range i.e. 100-200. &nbsp;Return an iterable object that returns all<br />
&nbsp; &nbsp; IP addresses in between.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Examples<br />
&nbsp; &nbsp; --------<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Single host:<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach(new IpRange('10.10.10.10') as $ip)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $ip . &quot;\n&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 10.10.10.10<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; All hosts on a private network:<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach(new IpRange('192.168.0.1-255') as $ip)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $ip . &quot;\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.254<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.255<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; All normal (not broadcast, or multicast) IP addresses:<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach(new IpRange('1-232.0-255.0-255.0-255') as $key =&gt; $value)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo &quot;$key =&gt; $value\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 0 =&gt; 1.0.0.0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 1 =&gt; 1.0.0.1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 2 =&gt; 1.0.0.2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 7315795 =&gt; 1.111.161.83<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 7315796 =&gt; 1.111.161.84<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; etc<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; */</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> IpRange implements Iterator<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Current position, used as the key</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ranges for each octet, l =&gt; low, h =&gt; high</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Most significant to least is aaa.bbb.ccc.ddd</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$d</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$ca</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of a</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cb</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of b</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cc</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of c</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cd</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of d</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$isValid</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// flag set when next() is call at end of ranges</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^(\d+|\d+-\d+)\.(\d+|\d+-\d+)\.(\d+|\d+-\d+)\.(\d+|\d+-\d+)$#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> InvalidArgumentException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid format. &nbsp;Each octet should either be a number between 0 and 255, or a range &quot;40-120&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Parse each octet and find the low/high values (high === low if there is no range specified)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$position</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$range</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$range</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$range</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$range</span><span style="color: #339933;">,</span> <span style="color: #000088;">$range</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check the IP address is at least mostly valid. &nbsp;We don't need to check for &lt;0 as our regex will reject it first.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$high</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> InvalidArgumentException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Invalid IP address. &nbsp;The octet '<span style="color: #006699; font-weight: bold;">$high</span>' cannot be greater than 255&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// If given a range like 255-0, flip the high/low value over</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$high</span><span style="color: #339933;">,</span> <span style="color: #000088;">$low</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$position</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'l'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'h'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">rewind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$this-&gt;ca}</span>.<span style="color: #006699; font-weight: bold;">{$this-&gt;cb}</span>.<span style="color: #006699; font-weight: bold;">{$this-&gt;cc}</span>.<span style="color: #006699; font-weight: bold;">{$this-&gt;cd}</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">count</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">rewind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ca</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cb</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">b</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">c</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">d</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> valid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">count</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Least significant to most. &nbsp;Null is our guard.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$position</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check if unable to generate the next IP address</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$position</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check if the value is less than the maximum for this </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// position, if so increment the value and stop. &nbsp;Otherwise set</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// this position to its lowest value, and continue onto the next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// highest position.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;c<span style="color: #006699; font-weight: bold;">$position</span>&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$position</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;c<span style="color: #006699; font-weight: bold;">$position</span>&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;c<span style="color: #006699; font-weight: bold;">$position</span>&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$position</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/07/ip-address-range-php-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VPN Week &#8211; IPSec on OpenBSD</title>
		<link>http://project-2501.net/index.php/2011/07/vpn-week/</link>
		<comments>http://project-2501.net/index.php/2011/07/vpn-week/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 19:12:50 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[vpn]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=326</guid>
		<description><![CDATA[This week I&#8217;ve spent a lot of time mucking around with IPSec VPNs. I thought I should informally document some of my settings in the hope that in a years time, when I&#8217;ve forgotten everything, I have some sort of base to build on. OS: OpenBSD >= 3.8 / Windows 7 Protocol: IPSec Part 1 [...]]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;ve spent a lot of time mucking around with IPSec VPNs.  I thought I should informally document some of my settings in the hope that in a years time, when I&#8217;ve forgotten everything, I have some sort of base to build on.</p>
<p><strong>OS:</strong> <a href="http://www.openbsd.org/">OpenBSD</a> >= 3.8 / Windows 7<br />
<strong>Protocol:</strong> <a href="http://en.wikipedia.org/wiki/IPsec">IPSec</a></p>
<h3>Part 1 &#8211; Common Configuration</h3>
<p>Make sure the following are enabled (via /etc/sysctl.conf or the sysctl command)</p>
<ul>
<li>net.inet.ip.forwarding=1</li>
<li>net.inet.esp.enable=1</li>
<li>net.inet.ah.enable=1</li>
</ul>
<p>OpenBSD is awesome thanks to ipsecctl; a 4 line configuration file is all you need for a basic setup.  But first we need to start isakmpd the IKEv1 key management daemon.  As we are using ipsecctl to manage most of the setup, we use the -K option to ignore the isakmpd.policy file.</p>
<p>To see the log files for isakmpd use -DA=nn to set the debug level of all classes to nn (where nn is between 0 and 99; I&#8217;d suggest 50).  Combine with with -d to keep the daemon running in the foreground.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">isakmpd -K -DA=50 -d &gt; /tmp/isakmpd.log 2&gt;&amp;1</div></div>
<p>ipsecctl is used in a similar way to everyone favourite tool pfctl.  To load a configuration just run:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ipsecctl -f /etc/ipsec.conf</div></div>
<p>Don&#8217;t forget to check your firewall as well, you&#8217;ll need to open up port 500 (UDP) and if you want to see the unencrypted traffic set skip on enc0.</p>
<p><em>(TODO: I also have &#8220;pass in on $if_ext inet proto esp from any to $server_me_ext&#8221; is this actually needed?)</em></p>
<h3>Part 2 &#8211; Site to Site IPSec OpenBSD <-> OpenBSD</h3>
<p>Open up /etc/ipsec.conf with vim, and then curse and moan that OpenBSD still doesn&#8217;t include vim in a default install.</p>
<p>Our site-site config looks like:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ike esp from 10.10.42.0/24 to 192.168.1.0/24 \<br />
&nbsp; &nbsp; &nbsp; &nbsp; peer 103.103.103.103 \<br />
&nbsp; &nbsp; &nbsp; &nbsp; main auth hmac-sha1 enc aes \<br />
&nbsp; &nbsp; &nbsp; &nbsp; quick auth hmac-sha1 enc aes \<br />
&nbsp; &nbsp; &nbsp; &nbsp; srcid 204.204.204.204 psk &quot;put a real pre shared key here&quot;</div></div>
<p>Where 10.10.42.0/24 is the local internal network, 192.168.1.0/24 is the remote network, 103.103.103.103 is the remote external IP and our eternal IP is 204.204.204.204.</p>
<p><em>(TODO: Fix this to use macros and define this nicely)</em></p>
<p>All that&#8217;s left is to run ipsecctl and then replicate these settings on your other OpenBSD box (all the settings will just be reversed) and you&#8217;re done.</p>
<h3>Part 3 &#8211; Road Warrior IPSec OpenBSD <-> Windows 7</h3>
<p>As you can see, still super simple.  We are using passive mode here so our server will not try to make a VPN connection, just listen for one.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ike passive from any to any \<br />
&nbsp; &nbsp; &nbsp; &nbsp; main auth hmac-sha1 enc aes group modp1024 \<br />
&nbsp; &nbsp; &nbsp; &nbsp; quick auth hmac-sha1 enc aes \<br />
&nbsp; &nbsp; &nbsp; &nbsp; psk &quot;good pre shared secrets are important&quot;</div></div>
<p><em>(TODO: from any to any, will this give access to the entire network?  Wouldn&#8217;t from 10.10.42.0/24 to any be better?)</em></p>
<p><em>(TODO: Why do we use DH Group 2 (modep1024) here and not above?)</em></p>
<p>On the Windows side I&#8217;m using <a href="http://www.shrew.net/software">Shrew Soft&#8217;s VPN client</a> which is not only free, but works well.</p>
<p>I created a new Site Configuration and used the follow settings (click the image for a full view).</p>
<p><a href="http://project-2501.net/gallery/other/shrew_vpn_client_config.png"><img src="http://project-2501.net/gallery/.thumbs/gallery_other_shrew_vpn_client_config.png.jpeg"></a></p>
<p>Of note:</p>
<ul>
<li>Disable auto configuration</li>
<li>Change authentication to mutual PSK and entered the PSK</li>
<li>Set exchange type to main</li>
<li>Set DH Exchange to Group 2 for both phase 1 and phase 2</li>
</ul>
<h3>Part 4 &#8211; Summary</h3>
<p>As you can tell I&#8217;m still learning this myself, and hopefully I&#8217;ll come back to this is a year, call my <em>old-self</em> an idiot and write a far better post.</p>
<p><strong>Note:</strong> I wrote this at 5am in the morning, so please excuse all the mistakes <img src='http://project-2501.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/07/vpn-week/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Smell</title>
		<link>http://project-2501.net/index.php/2011/07/code-smell/</link>
		<comments>http://project-2501.net/index.php/2011/07/code-smell/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 03:26:06 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=319</guid>
		<description><![CDATA[&#8220;In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem.&#8221; &#8212; Wikipedia I found this piece of code this morning, I think it counts as something gone terribly, terribly wrong: return displayItemDetails(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode, 14059111); (The code was in-line JavaScript, inserted into a onclick handler, generated [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>&#8220;In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem.&#8221; &#8212; <a href="http://en.wikipedia.org/wiki/Code_smell">Wikipedia</a></p></blockquote>
<p>I found this piece of code this morning, I think it counts as something gone terribly, terribly wrong:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">return displayItemDetails(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode, 14059111);</div></div>
<p><em>(The code was in-line JavaScript, inserted into a onclick handler, generated in PHP)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/07/code-smell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perlbal as a reverse proxy</title>
		<link>http://project-2501.net/index.php/2011/06/perlbal-as-a-reverse-proxy/</link>
		<comments>http://project-2501.net/index.php/2011/06/perlbal-as-a-reverse-proxy/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 03:15:14 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=306</guid>
		<description><![CDATA[I recently needed to set up a new reverse proxy as an alternative to pound, and for no particularly good reason chose Perlbal. The documentation is fairly good, but I didn&#8217;t find many (good) examples of working configurations. So I thought I&#8217;d include my very simple conf. LOAD vhosts # Management service via telnet CREATE [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to set up a new reverse proxy as an alternative to pound, and for no particularly good reason chose <a href="http://www.danga.com/perlbal/">Perlbal</a>.</p>
<p>The <a href="http://search.cpan.org/dist/Perlbal/lib/Perlbal/Manual.pod"> documentation </a> is fairly good, but I didn&#8217;t find many (good) examples of working configurations.  So I thought I&#8217;d include my very simple conf.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">LOAD vhosts<br />
<br />
<span style="color: #666666; font-style: italic;"># Management service via telnet</span><br />
CREATE SERVICE mgmt<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET role &nbsp; = management<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET listen = 127.0.0.1:<span style="color: #000000;">16000</span><br />
ENABLE mgmt<br />
<br />
<span style="color: #666666; font-style: italic;"># Web server</span><br />
CREATE POOL web<br />
&nbsp; &nbsp; &nbsp; &nbsp; POOL web ADD 10.10.42.41:<span style="color: #000000;">80</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Trac server</span><br />
CREATE POOL trac<br />
&nbsp; &nbsp; &nbsp; &nbsp; POOL trac ADD 10.10.42.42:<span style="color: #000000;">80</span><br />
<br />
CREATE SERVICE web_proxy<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET role = reverse_proxy<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET pool = web<br />
ENABLE web_proxy<br />
<br />
CREATE SERVICE trac_proxy<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET role = reverse_proxy<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET pool = trac<br />
ENABLE trac_proxy<br />
<br />
<span style="color: #666666; font-style: italic;"># Internally we use 'trac.internal.com' but externally it would</span><br />
<span style="color: #666666; font-style: italic;"># be 'trac.external.com'. &nbsp;So rather than creating a second </span><br />
<span style="color: #666666; font-style: italic;"># virtual host on our trac webserver, we re-write the header</span><br />
HEADER trac_proxy REMOVE Host<br />
HEADER trac_proxy INSERT Host:trac.internal.com<br />
<br />
<span style="color: #666666; font-style: italic;"># Listen on our external IP</span><br />
CREATE SERVICE selector<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET listen &nbsp;= 100.110.120.130:<span style="color: #000000;">80</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SET role &nbsp; &nbsp;= selector<br />
&nbsp; &nbsp; &nbsp; &nbsp; SET plugins = vhosts<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; VHOST external.com.au &nbsp; &nbsp; &nbsp; = web_proxy<br />
&nbsp; &nbsp; &nbsp; &nbsp; VHOST www.external.com.au &nbsp; = web_proxy<br />
&nbsp; &nbsp; &nbsp; &nbsp; VHOST trac.external.com.au &nbsp;= trac_proxy<br />
ENABLE selector</div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/06/perlbal-as-a-reverse-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (Requested URI is rejected)
Database Caching using disk
Object Caching 1046/1120 objects using disk

Served from: project-2501.net @ 2012-02-07 20:33:22 -->
