<?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>Farhad MalekpourFarhad Malekpour &#187; Scripts</title>
	<atom:link href="https://www.farhad.ca/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.farhad.ca</link>
	<description>Professional Work Weblog</description>
	<lastBuildDate>Tue, 02 Feb 2021 10:16:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>RBL Based IP to Location</title>
		<link>https://www.farhad.ca/2011/06/15/rbl-based-ip-to-location/</link>
		<comments>https://www.farhad.ca/2011/06/15/rbl-based-ip-to-location/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 05:40:18 +0000</pubDate>
		<dc:creator>Farhad Malekpour</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.farhad.ca/?p=46</guid>
		<description><![CDATA[I needed a very fast and effective way of fining geographical location of an IP address. I&#8217;ve already implemented a very nice interface located at Dayana Host IP Location, but due to web based system it&#8217;s not fast enough for what I need. Basically I&#8217;m trying to block access to login to certain mail boxes [...]]]></description>
				<content:encoded><![CDATA[<p>I needed a very fast and effective way of fining geographical location of an IP address. I&#8217;ve already implemented a very nice interface located at <a title="IP 2 Location" href="http://www.dayanahost.com/ip_location.cfm" target="_blank">Dayana Host IP Location</a>, but due to web based system it&#8217;s not fast enough for what I need.</p>
<p>Basically I&#8217;m trying to block access to login to certain mail boxes (managed by exim) from some countries. Routine is in Perl, so I can easily find IP address of a host using DNS lookup. All I needed was a service to give the location based on incoming IP address. I used <a title="RblDNSd" href="http://www.corpit.ru/mjt/rbldnsd.html" target="_blank">rbldnsd</a> and modified it to accept MaxMind country database and wola, it works as expected.</p>
<p>To use, first reverse the IP, just like what you do with RBL based spam lists. For instance 204.50.14.1 will be 1.14.50.204, then combine it with <strong>.rbloc.dayanadns.com</strong> and make a DNS query to find IP address, for example:</p>
<pre class="brush:plain">$host 1.14.50.204.rbloc.dayanadns.com</pre>
<p>That will give you two records, an A record and a TXT record.</p>
<p>&#8216;A&#8217; record will be in form of 127.0.X.Y wherre X is the ASCII code of the first letter of country code and Y is the second letter. For our example returned IP is 127.0.67.65 which means &#8216;CA&#8217; (C=&gt; 67, A=&gt;65).</p>
<p>TXT record is the complete country name, i.e. &#8216;Canada&#8217;.</p>
<p>Here is a sample perl script to get the country code:</p>
<pre class="brush:perl">#!/usr/bin/perl

use Socket;

$packed_ip = gethostbyname('1.14.50.204.rbloc.dayanadns.com');
if (defined $packed_ip)
{
    $ip_address = inet_ntoa($packed_ip);
    my(undef, undef, $d1, $d2) = split(/\./, $ip_address);
    $country_code = chr($d1).chr($d2);
}
print "Result address: ".$ip_address."\n";
print "Country code: ".$country_code."\n";</pre>
<p>and this one is in PHP:</p>
<pre class="brush:php">&lt;?php

$ip_address = gethostbyname('1.14.50.204.rbloc.dayanadns.com');
list($d1,$d2,$d3,$d4) = explode('.',$ip_address);
$country_code = chr($d3).chr($d4);

print "Result address: ".$ip_address."\n";
print "Country code: ".$country_code."\n";

?&gt;</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.farhad.ca/2011/06/15/rbl-based-ip-to-location/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Dayana MySQL Databases Check</title>
		<link>https://www.farhad.ca/2006/02/02/dayana-mysql-databases-check/</link>
		<comments>https://www.farhad.ca/2006/02/02/dayana-mysql-databases-check/#comments</comments>
		<pubDate>Fri, 03 Feb 2006 05:09:54 +0000</pubDate>
		<dc:creator>Farhad Malekpour</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.farhad.ca/2006/02/02/dayana-mysql-databases-check/</guid>
		<description><![CDATA[This script will check all tables within all MySQL databases of a server. Code written in Perl and can be executed at a root access shell with a command like this: perl dysqlcheck.pl No installation will be needed Just download to a folder and execute. You might need to change some configuration parameters at the [...]]]></description>
				<content:encoded><![CDATA[<p>This script will check all tables within all MySQL databases of a server.</p>
<p>Code written in Perl and can be executed at a root access shell with a command like this:</p>
<blockquote><p>perl dysqlcheck.pl</p></blockquote>
<p>No installation will be needed Just download to a folder and execute. You might need to change some configuration parameters at the beginning of the script itself.</p>
<p><span id="more-25"></span></p>
<p><a title="Dayana MySQL Database Check" href="http://farhad.ca/file/dysqlcheck.pl_">Download Dayana MySQL Database Check v1.0</a><br />
Current version: 1.0<br />
<!--more--></p>
<p>If you wish to do that on a linux shell do:</p>
<blockquote><p>cd<br />
wget http://farhad.ca/file/dysqlcheck.pl_<br />
mv -f dysqlcheck.pl_ dysqlcheck.pl<br />
perl dysqlcheck.pl</p></blockquote>
<p>F.Malekpour</p>
]]></content:encoded>
			<wfw:commentRss>https://www.farhad.ca/2006/02/02/dayana-mysql-databases-check/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
