<?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>Sosuke &#187; sosuke</title>
	<atom:link href="http://www.sosuke.com/index.php/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sosuke.com</link>
	<description>Dark music of the gods.</description>
	<lastBuildDate>Wed, 06 Jan 2010 01:34:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sizing the buttons on the NumericStepper</title>
		<link>http://www.sosuke.com/index.php/2010/01/05/sizing-the-buttons-on-the-numericstepper/</link>
		<comments>http://www.sosuke.com/index.php/2010/01/05/sizing-the-buttons-on-the-numericstepper/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 01:34:42 +0000</pubDate>
		<dc:creator>sosuke</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[skinning]]></category>

		<guid isPermaLink="false">http://www.sosuke.com/?p=53</guid>
		<description><![CDATA[So your working on a new RIA in Flash and you want to use the built in NumericStepper, or any other Flash component for that matter but you aren&#8217;t happy with the skin. You&#8217;ve already seen Customizing the NumericStepper component by Adobe and you&#8217;re ready to move past changing the color of the component and [...]]]></description>
			<content:encoded><![CDATA[<p>So your working on a new RIA in Flash and you want to use the built in NumericStepper, or any other Flash component for that matter but you aren&#8217;t happy with the skin. You&#8217;ve already seen <a href="http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7f42.html">Customizing the NumericStepper component</a> by Adobe and you&#8217;re ready to move past changing the color of the component and want to update the buttons. Every time I updated the component skin after it has been added to the Library in Flash and tested the Movie, the smaller button graphics I created get stretched and distorted. It was always 21 pixels wide and 12 pixels tall! The Adobe documentation on the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/fl/controls/NumericStepper.html">NumericStepper</a> didn&#8217;t provide any help in resizing these buttons that control the increase and decrease for the NumericStepper component.</p>
<p>What you need to do is open up the source and take a look to figure out what was going on. I found the source files here C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\Configuration\Component Source\ActionScript 3.0\User Interface\fl\controls\NumericStepper.as on my system. I found out what was going wrong by doing a quick search for that pesky 21 pixel width and found my answer starting on line 527.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> configUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">super</span>.configUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	upArrow = <span style="color: #0033ff; font-weight: bold;">new</span> BaseButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	copyStylesToChild<span style="color: #000000;">&#40;</span>upArrow, UP_ARROW_STYLES<span style="color: #000000;">&#41;</span>;
	upArrow.autoRepeat = <span style="color: #0033ff; font-weight: bold;">true</span>;
	upArrow.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">21</span>, <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000000;">&#41;</span>;
	upArrow.focusEnabled = <span style="color: #0033ff; font-weight: bold;">false</span>;
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>upArrow<span style="color: #000000;">&#41;</span>;
&nbsp;
	downArrow = <span style="color: #0033ff; font-weight: bold;">new</span> BaseButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	copyStylesToChild<span style="color: #000000;">&#40;</span>downArrow, DOWN_ARROW_STYLES<span style="color: #000000;">&#41;</span>;
	downArrow.autoRepeat = <span style="color: #0033ff; font-weight: bold;">true</span>;
	downArrow.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">21</span>, <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000000;">&#41;</span>;
	downArrow.focusEnabled = <span style="color: #0033ff; font-weight: bold;">false</span>;
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>downArrow<span style="color: #000000;">&#41;</span>;
&nbsp;
	inputField = <span style="color: #0033ff; font-weight: bold;">new</span> TextInput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	copyStylesToChild<span style="color: #000000;">&#40;</span>inputField, TEXT_INPUT_STYLES<span style="color: #000000;">&#41;</span>;
	inputField.<span style="color: #004993;">restrict</span> = <span style="color: #990000;">&quot;0-9<span style="">\\</span>-<span style="">\\</span>.<span style="">\\</span>,&quot;</span>;
	inputField.<span style="color: #004993;">text</span> = _value.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	inputField.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">21</span>, <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span>;
	inputField.focusTarget = <span style="color: #0033ff; font-weight: bold;">this</span> <span style="color: #0033ff; font-weight: bold;">as</span> IFocusManagerComponent;
	inputField.focusEnabled = <span style="color: #0033ff; font-weight: bold;">false</span>;
	inputField.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_IN</span>, passEvent<span style="color: #000000;">&#41;</span>;
	inputField.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_OUT</span>, passEvent<span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>inputField<span style="color: #000000;">&#41;</span>;
&nbsp;
	inputField.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">CHANGE</span>, onTextChange, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
	upArrow.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>ComponentEvent.BUTTON_DOWN, stepperPressHandler, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
	downArrow.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>ComponentEvent.BUTTON_DOWN, stepperPressHandler, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Ah ha! They set the size of the buttons when the component is initialized on the stage. You can&#8217;t edit this file to solve your problem though you&#8217;ll need to extend the fl.controls.NumericStepper class and override the configUI function to change the size of your buttons. I suspect there are several other instances of hard-coded component sizes in the Flash component library but you just need to look to the source they provided to extend the components to your liking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sosuke.com/index.php/2010/01/05/sizing-the-buttons-on-the-numericstepper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free US Zip Code Database</title>
		<link>http://www.sosuke.com/index.php/2009/05/30/free-us-zip-code-database/</link>
		<comments>http://www.sosuke.com/index.php/2009/05/30/free-us-zip-code-database/#comments</comments>
		<pubDate>Sun, 31 May 2009 01:28:06 +0000</pubDate>
		<dc:creator>sosuke</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[phpmyadmin]]></category>

		<guid isPermaLink="false">http://www.sosuke.com/?p=42</guid>
		<description><![CDATA[So as one of my sites grew I quickly found out that my zip code database was horribly incomplete with only 33234 records and it even had duplicates for some zip codes. I did some searching and came across a post about a zip code csv file but the post goes to what looks like [...]]]></description>
			<content:encoded><![CDATA[<p>So as one of my sites grew I quickly found out that my zip code database was horribly incomplete with only 33234 records and it even had duplicates for some zip codes. I did some searching and came across a post about a <a href="http://coolthingoftheday.blogspot.com/2008/04/free-us-zip-code-database-as-csv.html">zip code csv</a> file but the post goes to what looks like an empty page with no file. A little digging lead me to the <a href="http://mappinghacks.com/data/?C=M;O=A">zip code file</a> download page that gives you a csv with entries like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&quot;78701&quot;,&quot;Austin&quot;,&quot;TX&quot;,&quot;30.27127&quot;,&quot;-97.74103&quot;,&quot;-6&quot;,&quot;1&quot;</pre></div></div>

<p>Awesome! This csv file has 43191 unique records and has entries for each zip code my users have reported as missing. I started by looking up how to import a csv into MSSQL and followed an article called <a href="http://www.sqlteam.com/article/using-bulk-insert-to-load-a-text-file">Using BULK INSERT to Load a Text File</a> from which I came up with my query.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">BULK <span style="color: #993333; font-weight: bold;">INSERT</span> ZipCodes <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">'c:<span style="color: #000099; font-weight: bold;">\z</span>ipcodes.csv'</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #66cc66;">&#40;</span>FIELDTERMINATOR <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'&quot;&quot;,&quot;&quot;'</span><span style="color: #66cc66;">,</span> ROWTERMINATOR <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>It didn&#8217;t work and after a couple hours of trial and error I threw my hands up in the air and abandoned the bulk insert and fell back on another option of using phpMyAdmin. It sounds crazy but I setup the database in MySQL and imported the csv on the first attempt! Now to get it back to to MSSQL I exported the database as single row imports that looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`ZipCodes`</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'78701'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Austin'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'TX'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'30.27127'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-97.74103'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>A few quick find and replaces to change the database name and remove the ` characters and I was able to run them as queries on my MSSQL database in blocks of 5500 to prevent timeouts.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #66cc66;">&#91;</span>databaseName<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>ZipCodes<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'78701'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Austin'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'TX'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'30.27127'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-97.74103'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>It&#8217;s crucial to have a fairly complete zip code database for distance searching on my <a href="http://diveintothepool.com">free online dating</a> site and I&#8217;m glad I got this sorted out and updated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sosuke.com/index.php/2009/05/30/free-us-zip-code-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocking IP addresses by country on IIS shared hosting</title>
		<link>http://www.sosuke.com/index.php/2009/05/20/blocking-ip-addresses-by-country-on-iis-shared-hosting/</link>
		<comments>http://www.sosuke.com/index.php/2009/05/20/blocking-ip-addresses-by-country-on-iis-shared-hosting/#comments</comments>
		<pubDate>Thu, 21 May 2009 06:23:08 +0000</pubDate>
		<dc:creator>sosuke</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[shared hosting]]></category>

		<guid isPermaLink="false">http://www.sosuke.com/?p=32</guid>
		<description><![CDATA[On a shared hosting environment you often won&#8217;t have access to ban IP addresses on the IIS level and my shared host didn&#8217;t offer the Firewall module for Plesk so I had to come up with a programmatic way of blocking large blocks of IPs. You can setup in your web.config file something called a [...]]]></description>
			<content:encoded><![CDATA[<p>On a shared hosting environment you often won&#8217;t have access to ban IP addresses on the IIS level and my shared host didn&#8217;t offer the Firewall module for Plesk so I had to come up with a programmatic way of blocking large blocks of IPs. You can setup in your web.config file something called a HTTPModule that works before the page is delivered to the client computer. For this sample I added a key and value to my web.config file that holds my comma separated IP list that I want to block. Since I&#8217;m running a site that is focused on the United States there isn&#8217;t much overlap on the /24 block area 255.255.255.* so I am only checking the first 3 digit blocks for matches. When a request comes in IpTwentyFourBlockingModule will check the users IP address against the key value blockiptwentyfour to see if there is a match and if it is a match will return 403 forbidden to the client browser, banned! </p>
<p>Coming up with a IP list is another problem. I found <a href="http://iplocationtools.com">IP Location Tools</a> that gives out an API that generates a updated <a href="http://iplocationtools.com/ip_country_block_iptables.php">list of IPs for a given country</a>. The problem is the list gets broken out into IP blocks other than /24, you&#8217;ll see all ranges of IP blocks that get very complicated very fast and more than I wanted to try and pull off in a days work. I wrote a Flash ActionScript 3 application to consume this data and give me a list of unique IPs 255.255.255 that I could then drop in as the value for blockiptwentyfour. I then added IP tracking for new users and have had to ban some rogue /24 blocks that escaped this list but its kept them at bay and more manageable for now. I&#8217;ve already had a colleague suggest that this is still only a stopgap at best and I should develop some kind of throttling system to help prevent spam when I&#8217;m not around to watch the site like a hawk.</p>
<p>web.config</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;blockiptwentyfour&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;41.210.29,41.210.28&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IpTwentyFourBlockingModule&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;IpTwentyFourBlockingModule&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>IpTwentyFourBlockingModule.cs &#8211; put this is in your App_Code</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080;">#region Using</span>
&nbsp;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Configuration</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Specialized</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080;">#endregion</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Block the response to certain IP addresses</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> IpTwentyFourBlockingModule <span style="color: #008000;">:</span> IHttpModule
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #008080;">#region IHttpModule Members</span>
&nbsp;
    <span style="color: #0600FF;">void</span> IHttpModule.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Nothing to dispose; </span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">void</span> IHttpModule.<span style="color: #0000FF;">Init</span><span style="color: #000000;">&#40;</span>HttpApplication context<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        context.<span style="color: #0000FF;">BeginRequest</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>context_BeginRequest<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Checks the requesting IP address in the collection</span>
    <span style="color: #008080; font-style: italic;">/// and block the response if it's on the list.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> context_BeginRequest<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">string</span> ip <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">UserHostAddress</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> tempIpArray <span style="color: #008000;">=</span> ip.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'.'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> iptwentyfour <span style="color: #008000;">=</span> tempIpArray<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.&quot;</span> <span style="color: #008000;">+</span> tempIpArray<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.&quot;</span> <span style="color: #008000;">+</span> tempIpArray<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_IpAdresses.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>iptwentyfour<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">StatusCode</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">403</span><span style="color: #008000;">;</span>
            HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> StringCollection _IpAdresses <span style="color: #008000;">=</span> FillBlockedIps<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Retrieves the IP addresses from the web.config</span>
    <span style="color: #008080; font-style: italic;">/// and adds them to a StringCollection.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;A StringCollection of IP addresses.&lt;/returns&gt;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> StringCollection FillBlockedIps<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        StringCollection col <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> raw <span style="color: #008000;">=</span> ConfigurationManager.<span style="color: #0000FF;">AppSettings</span>.<span style="color: #0000FF;">Get</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;blockiptwentyfour&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> ip <span style="color: #0600FF;">in</span> raw.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">','</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            col.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>ip.<span style="color: #0000FF;">Trim</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">return</span> col<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>collectipaddresses.as</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> myRequest<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;http://iplocationtools.com/country_query.php?country=CI,SN,GH,NA,NG&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #004993;">loader</span>.<span style="color: #004993;">dataFormat</span> = <span style="color: #004993;">URLLoaderDataFormat</span>.<span style="color: #004993;">TEXT</span>;
<span style="color: #004993;">loader</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">COMPLETE</span>, handleComplete<span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">loader</span>.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>myRequest<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> handleComplete<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #009900;">//trace(loader.data.replace(/\n/g, &quot;|&quot;));</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> ipArray<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #004993;">loader</span>.<span style="color: #004993;">data</span>.<span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">/</span>\n<span style="color: #000000; font-weight: bold;">/</span>g, <span style="color: #990000;">&quot;|&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;|&quot;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>ipArray.<span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span>;
	setTwentyFourBlock<span style="color: #000000;">&#40;</span>ipArray<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> setTwentyFourBlock<span style="color: #000000;">&#40;</span>ipArray<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span>	shortIpArray<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span>	lastUniqueIp<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> ip<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #0033ff; font-weight: bold;">in</span> ipArray<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> tempIpArray<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = ip.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> stringCurrentIp<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = tempIpArray<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">+</span>tempIpArray<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">+</span>tempIpArray<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;.0&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>stringCurrentIp <span style="color: #000000; font-weight: bold;">!</span>= lastUniqueIp<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			lastUniqueIp = stringCurrentIp;
			shortIpArray.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>stringCurrentIp<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>shortIpArray.<span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>shortIpArray.<span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">','</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>All of this work has really kept my <a href="http://www.diveintothepool.com/">free online dating</a> site almost spam free for now but I&#8217;m adding IP blocks I&#8217;ve missed from time to time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sosuke.com/index.php/2009/05/20/blocking-ip-addresses-by-country-on-iis-shared-hosting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
