JSFiddle - React, Tailwind, and code Playground
HTML
<p>This tool will convert deny and allow rules from an .htaccess file into the equivilant in IIS. They can then be added to the web.config in the system.webServer/security/ipSecurity section.
<p>
<label>Source .htaccess Code:</label>
<textarea name="source" class="source" rows="25"></textarea>
</p>
<p>
<label>Convert to web.config Code:</label>
<button name="run" class="run">Run</button>
</p>
<p>
<label>Results:</label>
<textarea name="results" class="results" rows="25" readonly></textarea>
</p>
<p>
Recomended Blacklists: <a href="http://www.wizcrafts.net/nigerian-blocklist.html" target="_blank">Nigerian</a>, <a href="http://www.wizcrafts.net/russian-blocklist.html" target="_blank">Russian</a>, <a href="http://www.wizcrafts.net/lacnic-blocklist.html" target="_blank">Lacnic</a>, <a href="http://www.wizcrafts.net/chinese-blocklist.html" target="_blank">Chinese</a>
</p>
<p>You will need to run the following in an administrator command prompt or you will get an error when you add any of these rules to your web.config.
<pre><code>%windir%\system32\inetsrv\AppCmd.exe unlock config -section:system.webServer/security/ipSecurity</code></pre>
CSS
body{
padding: 1em 2em;
}
.source, .results {
width: 100%;
padding: .5em;
}
JavaScript
$(".run").click(function() {
// Get .htaccess rules
var source = $(".source").val();
// Move allow from to end of line
source = source.replace(/allow +from +(.*)$/gm, "$1 allow from");
// Add allow from to each individual item
source = source.replace(/(\/\d\d?)(?=.* +allow +from$)/gm, "$1 allowed=\"true\"");
// Remove allow and deny from text
source = source.replace(/deny +from +/g, "");
source = source.replace(/ allow from/g, "");
// Move each address to it's own line
source = source.replace(/(\d|="true") (\d)/g, "$1\n$2");
// Convert /xx style masks to x.x.x.x style network mask
source = source.replace(/(\d)\/32/g, "$1\" subnetMask=\"255.255.255.255\" />");
source = source.replace(/(\d)\/31/g, "$1\" subnetMask=\"255.255.255.254\" />");
source = source.replace(/(\d)\/30/g, "$1\" subnetMask=\"255.255.255.252\" />");
source = source.replace(/(\d)\/29/g, "$1\" subnetMask=\"255.255.255.248\" />");
source = source.replace(/(\d)\/28/g, "$1\" subnetMask=\"255.255.255.240\" />");
source = source.replace(/(\d)\/27/g, "$1\" subnetMask=\"255.255.255.224\" />");
source = source.replace(/(\d)\/26/g, "$1\" subnetMask=\"255.255.255.192\" />");
source = source.replace(/(\d)\/25/g, "$1\" subnetMask=\"255.255.255.128\" />");
source = source.replace(/(\d)\/24/g, "$1\" subnetMask=\"255.255.255.0\" />");
source = source.replace(/(\d)\/23/g, "$1\" subnetMask=\"255.255.254.0\" />");
source = source.replace(/(\d)\/22/g, "$1\" subnetMask=\"255.255.252.0\" />");
source = source.replace(/(\d)\/21/g, "$1\" subnetMask=\"255.255.248.0\" />");
source = source.replace(/(\d)\/20/g, "$1\" subnetMask=\"255.255.240.0\" />");
source = source.replace(/(\d)\/19/g, "$1\" subnetMask=\"255.255.224.0\" />");
source = source.replace(/(\d)\/18/g, "$1\" subnetMask=\"255.255.192.0\" />");
source = source.replace(/(\d)\/17/g, "$1\" subnetMask=\"255.255.128.0\" />");
...