<?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>Matt Daubneys Blog &#187; python</title>
	<atom:link href="http://daubers.co.uk/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://daubers.co.uk</link>
	<description></description>
	<lastBuildDate>Sat, 17 Jul 2010 20:07:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Denyhosts Stats</title>
		<link>http://daubers.co.uk/2009/05/25/denyhosts-stats/</link>
		<comments>http://daubers.co.uk/2009/05/25/denyhosts-stats/#comments</comments>
		<pubDate>Mon, 25 May 2009 14:44:20 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[webbyness]]></category>
		<category><![CDATA[denyhosts]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://daubers.co.uk/?p=187</guid>
		<description><![CDATA[I have been told many many times that moving ssh to a different port (i.e. other than 22) makes your machine more secure. I do see some wisdom in this, however, I&#8217;ve decided to put it to the test. I have been using Denyhosts to stop brute force attacks on my ssh servers for some [...]]]></description>
			<content:encoded><![CDATA[<p>I have been told many many times that moving ssh to a different port (i.e. other than 22) makes your machine more secure. I do see some wisdom in this, however, I&#8217;ve decided to put it to the test. I have been using Denyhosts to stop brute force attacks on my ssh servers for some time now, and on my most recent server, the attacks per day are fairly regular, as seen in the graph.</p>
<p style="text-align: left;">
<div id="attachment_188" class="wp-caption aligncenter" style="width: 490px"><a href="http://daubers.co.uk/wp-content/uploads/2009/05/plot.png"><img class="size-full wp-image-188" title="Plot of Deny Hosts Blocks per Day" src="http://daubers.co.uk/wp-content/uploads/2009/05/plot.png" alt="Plot of Deny Hosts Blocks per Day" width="480" height="360" /></a><p class="wp-caption-text">Plot of Deny Hosts Blocks per Day</p></div>
<p style="text-align: left;">At the end of June I will stop using port 22 and start using another random port. I&#8217;ll then collect data for 3 months and at the end of september do another blog post showing the difference. I also have another server that I will repeat this experiment on, but that one will be 3 months behind.</p>
<p style="text-align: left;">Hopefully then I will have a nice sturdy scientific answer as to how much more protection moving ssh to a different port gives <img src='http://daubers.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: left;">The code I used to generate this graph is given below for reference.</p>
<pre lang="python" line="1">
import os
import matplotlib
import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.mlab as mlab
matplotlib.use('Agg')

datelist = {}
rootdir = './'

def plot_all():
	#first convert dict to a set of x values and a set of y values
	keys = datelist.keys()
	keys.sort()
	values = []
	times = []
	for key in keys:
		values.append(datelist[key])
	#now convert the keys into time format
		times.append(datetime.datetime.strptime(key, "%Y-%m-%d"))

	#now we're ready to plot with matplotlib
	months   = mdates.MonthLocator()  # every month
	days	= mdates.DayLocator()
	yearsFmt = mdates.DateFormatter('%b')
	dayFmt = mdates.DateFormatter('%d')

	fig = plt.figure()
	ax = fig.add_subplot(111)
	dates = range(times[0].toordinal(), times[-1].toordinal())
	ax.bar(times,values,width=1)

	ax.set_xlabel('Date')
	ax.set_ylabel('Number of Hosts Denied')

	#ax.plot(times, values)
	#ax.xaxis.set_major_formatter(yearsFmt)
	#ax.xaxis.set_major_locator(months)
	#ax.xaxis.set_minor_formatter(dayFmt)
	#ax.xaxis.set_minor_locator(days)
	ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
	fig.autofmt_xdate()
        fig.savefig("plot.png")

def countup(file):
	f = open(file, 'r')
	for line in f.readlines():
		#split by spaces to get the date
		line = line.split(" ")
		#now see if this is already in the list
		newline = False
		for part in line:
			if part == "new":
				newline = True
			else:
				continue
		if newline == True:
			n = 0
			if line[0] in datelist:
				datelist[line[0]] = datelist[line[0]] + 1
			else:
				datelist[line[0]] = 1
	f.close()

for subdir, dirs, files in os.walk(rootdir):
	for file in files:
		if not file[-2:] == "py" and file.split(".")[0] == "denyhosts":
			countup(rootdir + file)

keys = datelist.keys()
keys.sort()

for key in keys:
	print("%s, %s" % (key,datelist[key]))
plot_all()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://daubers.co.uk/2009/05/25/denyhosts-stats/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
