<?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>Pario TechnoBlob &#187; diff</title>
	<atom:link href="http://pario.no/tag/diff/feed/" rel="self" type="application/rss+xml" />
	<link>http://pario.no</link>
	<description>A cronological documentation test project, nothing serious, really!</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:17:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Compare a remote file with a local file using ssh and diff</title>
		<link>http://pario.no/2010/09/09/compare-a-remote-file-with-a-local-file-using-ssh-and-diff/</link>
		<comments>http://pario.no/2010/09/09/compare-a-remote-file-with-a-local-file-using-ssh-and-diff/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 19:52:22 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://pario.no/?p=1394</guid>
		<description><![CDATA[# ssh user@example.com cat /path/to/remotefile &#124; diff /path/to/localfile -]]></description>
			<content:encoded><![CDATA[<pre>
# ssh user@example.com cat /path/to/remotefile | diff /path/to/localfile -</pre>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMTAvMDkvMDkvY29tcGFyZS1hLXJlbW90ZS1maWxlLXdpdGgtYS1sb2NhbC1maWxlLXVzaW5nLXNzaC1hbmQtZGlmZi88d3B0Yj5Db21wYXJlIGEgcmVtb3RlIGZpbGUgd2l0aCBhIGxvY2FsIGZpbGUgdXNpbmcgc3NoIGFuZCBkaWZmPHdwdGI%2BaHR0cDovL3BhcmlvLm5vPHdwdGI%2BUGFyaW8gVGVjaG5vQmxvYg%3D%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2010/09/09/compare-a-remote-file-with-a-local-file-using-ssh-and-diff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting changes to your network services/damons</title>
		<link>http://pario.no/2007/04/30/detecting-changes-to-your-network-servicesdamons/</link>
		<comments>http://pario.no/2007/04/30/detecting-changes-to-your-network-servicesdamons/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 10:30:23 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[basename]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ping]]></category>

		<guid isPermaLink="false">http://hhj.no/wordpress/2007/04/30/detecting-changes-to-your-network-servicesdamons/</guid>
		<description><![CDATA[This is a tutorial to detect changes in port from hosts on your network. The basic approach is to ping every available address upon your subnet and see which ones are up by detecting replies. If you install the package libperl-net-ping you can use the following script to see which hosts upon your LAN are [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tutorial to detect changes in port from hosts on your network.<br />
The basic approach is to ping every available address upon your subnet and see which ones are up by detecting replies.</p>
<p>If you install the package libperl-net-ping you can use the following script to see which hosts upon your LAN are alive:</p>
<pre>
#!/usr/bin/perl -w

use strict;
use Net::Ping;

my $LAN = "192.168.1.";

foreach my $octet (1 .. 255)
{
	my $pinger = Net::Ping-&gt;new();
	if ( $pinger-&gt;ping( $LAN . $octet ) )
	{
		print  $LAN . $octet . "\n";
	}
	$pinger-&gt;close();
}</pre>
<p>Save the script as /usr/local/bin/scan-lan and make sure it&#8217;s executable by running chmod 755 /usr/local/bin/scan-lan.</p>
<p>This would give you a list of IP addresses which might look like the following:</p>
<pre>
192.168.1.1
192.168.1.2
192.168.1.10
192.168.1.50
192.168.1.90</pre>
<p>With a list like that saved to text file you can now start scanning your network for services.</p>
<p>In order to detect changes to our network we wish to record all the services on the machines in our LAN then later rescan to detect anything different.</p>
<p>Using the scan-lan and nmap we can create a file for each machine that&#8217;s up containing its services.</p>
<p>Save this script as /usr/local/bin/make-baseline, and make it executable with &#8220;chmod 755 /usr/local/bin/make-baseline&#8221;:</p>
<pre>
#!/bin/sh

mkdir -p /var/log/scans

for i in `/usr/local/bin/scan-lan` ; do
    nmap -sV $i | grep ' open ' &gt; /var/log/scans/$i.base
done</pre>
<p>This is our baseline scan. With this in hand we have a list of all the hosts upon a lan which are currently up, and the services they are running.</p>
<p>Now we just to write another script to compare the current state to that we recorded in our baseline, this will notify us of changes.</p>
<p>The following script can do that job for us, save it as /usr/local/bin/scan-services:</p>
<pre>
#!/bin/sh

if [ ! -d /var/log/scans ]; then
   echo "Baseline directory isn't present"
   exit
fi

#
#  Scan all the machines
#
for i in `/usr/local/bin/scan-lan` ; do
    nmap -sV $i | grep ' open ' &gt; /var/log/scans/$i.log
done

#
# Cleanup
#
rm /var/log/scans/*-added.txt
rm /var/log/scans/*-removed.txt
cd /var/log/scans/

#
# Find new and removed
#
for i in /var/log/scans/*.log; do
  diff --context $i ${i/.log/}.base | grep '^+ ' &gt; `basename $i .log`-added.txt
  diff --context $i ${i/.log/}.base | grep '^- ' &gt; `basename $i .log`-removed.txt
done

#
#  Now show the results
#
for i in /var/log/scans/*-added.txt; do
    if [ -s $i ]; then
      echo " "
      echo "The machine `basename $i -added.txt` has had the following services added:"
      cat $i
      echo " "
    fi
done

for i in /var/log/scans/*-removed.txt; do
    if [ -s $i ]; then
      echo " "
      echo "The machine `basename $i -removed.txt` has had the following services removed:"
      cat $i
      echo " "
    fi
done</pre>
<p>If you make this executable and run it you should see no output, as your current network hasn&#8217;t changed in the past few minutes.</p>
<p>Delete a line or two from one or more of the .base files in the /var/log/scans directory and run it again.</p>
<p>This time you should see output like this:</p>
<pre>
The machine 192.168.1.1 has had the following services added:
+ 8889/tcp open  http        GNUMP3d streaming server 2.9

The machine 127.0.0.1 has had the following services removed:
- 19/tcp   open  discard?</pre>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMDQvMzAvZGV0ZWN0aW5nLWNoYW5nZXMtdG8teW91ci1uZXR3b3JrLXNlcnZpY2VzZGFtb25zLzx3cHRiPkRldGVjdGluZyBjaGFuZ2VzIHRvIHlvdXIgbmV0d29yayBzZXJ2aWNlcy9kYW1vbnM8d3B0Yj5odHRwOi8vcGFyaW8ubm88d3B0Yj5QYXJpbyBUZWNobm9CbG9i";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/04/30/detecting-changes-to-your-network-servicesdamons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diff two files, display the results in two clever colums</title>
		<link>http://pario.no/2007/03/14/diff-two-files-display-the-results-in-two-clever-colums/</link>
		<comments>http://pario.no/2007/03/14/diff-two-files-display-the-results-in-two-clever-colums/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 14:23:45 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[diff]]></category>

		<guid isPermaLink="false">http://hhj.no/wordpress/2007/03/14/diff-two-files-display-the-results-in-two-clever-colums/</guid>
		<description><![CDATA[diff -y index.php index2.php]]></description>
			<content:encoded><![CDATA[<p><code>diff -y index.php index2.php</code></p>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMDMvMTQvZGlmZi10d28tZmlsZXMtZGlzcGxheS10aGUtcmVzdWx0cy1pbi10d28tY2xldmVyLWNvbHVtcy88d3B0Yj5EaWZmIHR3byBmaWxlcywgZGlzcGxheSB0aGUgcmVzdWx0cyBpbiB0d28gY2xldmVyIGNvbHVtczx3cHRiPmh0dHA6Ly9wYXJpby5ubzx3cHRiPlBhcmlvIFRlY2hub0Jsb2I%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/03/14/diff-two-files-display-the-results-in-two-clever-colums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

