<?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>108.bz</title>
	<atom:link href="http://www.108.bz/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.108.bz</link>
	<description>Wandering futilities...</description>
	<lastBuildDate>Sat, 03 Jul 2010 15:53:31 +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>FortiGate firewall clusters group-id</title>
		<link>http://www.108.bz/posts/it/fortigate-firewall-clusters-group-id/</link>
		<comments>http://www.108.bz/posts/it/fortigate-firewall-clusters-group-id/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 15:53:31 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[FortiGate]]></category>
		<category><![CDATA[HA]]></category>
		<category><![CDATA[High Availability]]></category>
		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=527</guid>
		<description><![CDATA[A newly installed FortiGate cluster (a simple two node HA active-passive setup) and some packet loss issues&#8230; Ping from the LAN side to the Internet (or from the firewall itself) resulted in about 20% packet loss, while the other way around (WAN to firewall&#8217;s main public IP) didn&#8217;t work at all. I used the following [...]]]></description>
			<content:encoded><![CDATA[<p>A newly installed FortiGate cluster (a simple two node HA active-passive setup) and some packet loss issues&#8230;<br />
Ping from the LAN side to the Internet (or from the firewall itself) resulted in about 20% packet loss, while the other way around (WAN to firewall&#8217;s main public IP) didn&#8217;t work at all.</p>
<p>I used the following command to check my MAC addresses:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FORTIGATE-PRI # diagnose hardware deviceinfo nic wan1<br />
[..]<br />
Current_HWaddr &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;00:09:0f:09:00:08<br />
Permanent_HWaddr &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;00:09:0f:d1:be:ef<br />
[..]</div></div>
<p>Then resorted to the &#8220;show mac&#8221; switches facilites (some Cisco, some ProCurve) to know on which network ports that particular MAC lied&#8230; Only to discover that the cluster&#8217;s &#8220;logical&#8221; MAC address (00:09:0f:09:00:08) wasn&#8217;t really located where I expected it to be.<br />
Well, FortiGate&#8217;s MAC addresses <i>aren&#8217;t randomly generated</i>. They have predictable values that depend on the firewall&#8217;s port number. The eight port (or wan1, in my case) will always have a virtual MAC as the one above. What will happen if you have two clusters (as we had) sitting on the same L2 network segment (on the same broadcast domain, that is)? You said MAC address conflict? You&#8217;re right.<br />
The solution is simple, use the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">group-id</span> directive to tweak the logical MAC address, i.e.:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">config system ha<br />
&nbsp; &nbsp; set group-id 10<br />
end</div></div>
<p>Changes the second right-most bytes of the MAC, from 00 to 0a:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">before &nbsp;00:09:0f:09:00:08<br />
after &nbsp; 00:09:0f:09:0a:08</div></div>
<p>Point is that the &#8220;FortiOS High Availablity <a href="http://docs.fortinet.com/fgt/handbook/fortigate-ha-40-mr2.pdf">Handbook</a>&#8221; explains the case very thoroughly! See page 192, paragraph &#8220;Diagnosing packet loss with two FortiGate HA clusters in the same broadcast domain&#8221;. We&#8217;re so used to discardable product documentation that sometimes we don&#8217;t even try to look for clues where they should normally reside.<br />
Instead of troubleshooting, this time, I should really have Read The (unexpectedly) Fine Manual&#8230; </p>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=527" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/fortigate-firewall-clusters-group-id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unknown devices on HP servers</title>
		<link>http://www.108.bz/posts/it/unknown-devices-on-hp-servers/</link>
		<comments>http://www.108.bz/posts/it/unknown-devices-on-hp-servers/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 12:14:51 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[HP]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=508</guid>
		<description><![CDATA[Following up on the &#8220;Unknown devices on IBM servers&#8221; post, let me talk about a similar situation with HP machines (DL180 G6, in my case). The device that Windows fails to identify is this one: PCI\VEN_8086&#38;DEV_3A22&#38;CC_0106 More info can be found by looking up the IDs in the pci.ids file (as I often do), or [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on the &#8220;Unknown devices on IBM servers&#8221; <a href="http://www.108.bz/posts/it/unknown-devices-on-ibm-servers/">post</a>, let me talk about a similar situation with HP machines (DL180 G6, in my case).</p>
<p>The device that Windows fails to identify is this one:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PCI\VEN_8086&amp;DEV_3A22&amp;CC_0106</div></div>
<p>More info can be found by looking up the IDs in the <a href="http://pciids.sourceforge.net/pci.ids">pci.ids</a> file (as I often do), or by means of the various &#8220;Unkown Device Identifier&#8221; type of software (e.g. <a href="http://www.zhangduo.com/udi.html">this one</a>). If you have a Linux machine at  hand, such a one-liner may suit you:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># sed -n -e '/^8086/,/3a22/p' /usr/share/misc/pci.ids | sed -n -e '1p;$p'<br />
8086 &nbsp;Intel Corporation<br />
&nbsp; &nbsp; &nbsp; &nbsp; 3a22 &nbsp;82801JI (ICH10 Family) SATA AHCI Controller</div></div>
<p>What&#8217;s missing is an Intel SATA driver; needless to say that you won&#8217;t find it anywere on HP site.<br />
I downloaded and installed the <i>Rapid Storage Technology Driver</i> from Intel&#8217;s web site (<a href="http://downloadcenter.intel.com/Detail_Desc.aspx?agr=Y&#038;DwnldID=15251&#038;lang=eng">here</a>). A 280KB download named &#8220;STOR_all32_f6flpy_9.6.0.1014_PV.zip&#8221; fixed things up for me.<br />
Maybe the proper thing to try would&#8217;ve been the latest (March 2010) <a href="http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareIndex.jsp?lang=en&#038;cc=us&#038;prodNameId=3716247&#038;prodTypeId=18964&#038;prodSeriesId=3716246&#038;swLang=13&#038;taskId=135&#038;swEnvOID=1005">Proliant Support Pack</a>, but it&#8217;s a big download and I didn&#8217;t have the time. Also, the onboard SATA controller isn&#8217;t really used (the additional SAS RAID is, instead) and I just wanted to get rid of the yellow warning sign in Device Manager.</p>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=508" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/unknown-devices-on-hp-servers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The offline ACU CD</title>
		<link>http://www.108.bz/posts/it/the-offline-acu-cd/</link>
		<comments>http://www.108.bz/posts/it/the-offline-acu-cd/#comments</comments>
		<pubDate>Fri, 28 May 2010 10:03:12 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[FC]]></category>
		<category><![CDATA[Fibre Channel]]></category>
		<category><![CDATA[HP]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=504</guid>
		<description><![CDATA[Well hidden in their labyrinthian web site, you may stumble upon HP&#8217;s &#8220;Array Configuration Utility (ACU) Offline CD for Smart Array&#8221;. A plain bootable CD, useful when ACU simply can&#8217;t be installed on the server/OS. Example: I needed to tweak SSP (Selective Storage Presentation) settings on an MSA1000, connected through Fiber Channel HBAs (QLogic) to [...]]]></description>
			<content:encoded><![CDATA[<p>Well <a href="http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en&#038;cc=us&#038;prodTypeId=15351&#038;prodSeriesId=1121516&#038;prodNameId=3288134&#038;swEnvOID=2025&#038;swLang=8&#038;mode=2&#038;taskId=135&#038;swItem=MTX-f0790470403f4da3bd94126308">hidden</a> in their labyrinthian web site, you may stumble upon HP&#8217;s &#8220;Array Configuration Utility (ACU) Offline CD for Smart Array&#8221;. A plain bootable CD, useful when ACU simply can&#8217;t be installed on the server/OS.<br />
Example: I needed to tweak SSP (Selective Storage Presentation) settings on an MSA1000, connected through Fiber Channel HBAs (QLogic) to some rather old HP DL580 G2. The servers were running VMware ESX 3i 3.5.0 build-207095 (the latest one compatibile with those kind of CPUs) with no management agents installed. Since the MSA1000 can only be managed &#8220;in-band&#8221; or via a non standard serial cable the Customer, of course, lost long ago, I rebooted an ESX host with the offline ACU CD&#8230;<br />
Before that, I also tried a standard SmartStart CD, but it didn&#8217;t work. I had version 7.80 (way younger than the servers/HBAs), but no link lights on the FC switch, meaning no firmware loaded on the QLogic card, meaning no SmartStart supported HBA drivers. Offline ACU CD version 8.20.19 worked like a charm instead. Find its latest release by <a href="http://www.google.com/search?hl=en&#038;source=hp&#038;q=site%3Ahp.com+array+configuration+utility">searching</a> &#8220;array configuration utility&#8221; on <a href="http://www.hp.com">hp.com</a>, clicking on &#8220;Download software&#8221;, then &#8220;Linux GUI ACU&#8221;. Download link is somewhere in that page&#8230;</p>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=504" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/the-offline-acu-cd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the CLI to manage Windows DNS servers</title>
		<link>http://www.108.bz/posts/uncategorized/using-the-cli-to-manage-windows-dns-servers/</link>
		<comments>http://www.108.bz/posts/uncategorized/using-the-cli-to-manage-windows-dns-servers/#comments</comments>
		<pubDate>Mon, 24 May 2010 14:16:46 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=486</guid>
		<description><![CDATA[(This, for once, is going to be quick.) Did you know about the Dnscmd.exe command? Read about it here and here. It&#8217;s the command-line/DOS prompt way to configure Microsoft&#8217;s DNS servers&#8230; If you need to create many zones/records at once, it saves you lots of clicks. Here&#8217;s how to add six DNS zones (same domain [...]]]></description>
			<content:encoded><![CDATA[<p>(This, for once, is going to be quick.)<br />
Did you know about the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">Dnscmd.exe</span> command? Read about it <a href="http://technet.microsoft.com/en-us/library/cc778513(WS.10).aspx">here</a> and <a href="http://www.petri.co.il/dnscmd_command_in_windows_2000_2003.htm">here</a>. It&#8217;s the command-line/DOS prompt way to configure Microsoft&#8217;s DNS servers&#8230; If you need to create many zones/records at once, it saves you lots of clicks.<br />
Here&#8217;s how to add six DNS zones (same domain name, different TLD). With the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">/DSPrimary</span> option, the zone will be stored into Active Directory (rather than a file).</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dnscmd /ZoneAdd domainname.bz &nbsp;/DSPrimary<br />
dnscmd /ZoneAdd domainname.biz /DSPrimary<br />
dnscmd /ZoneAdd domainname.com /DSPrimary<br />
dnscmd /ZoneAdd domainname.eu &nbsp;/DSPrimary<br />
dnscmd /ZoneAdd domainname.net /DSPrimary<br />
dnscmd /ZoneAdd domainname.org /DSPrimary</div></div>
<p>And here&#8217;s how to add the same &#8220;A&#8221; record (named &#8220;www&#8221;) to each of the zones created above.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dnscmd dns-dc-hostname /RecordAdd domainname.bz &nbsp;www A 10.0.0.123<br />
dnscmd dns-dc-hostname /RecordAdd domainname.biz www A 10.0.0.123<br />
dnscmd dns-dc-hostname /RecordAdd domainname.com www A 10.0.0.123<br />
dnscmd dns-dc-hostname /RecordAdd domainname.eu &nbsp;www A 10.0.0.123<br />
dnscmd dns-dc-hostname /RecordAdd domainname.net www A 10.0.0.123<br />
dnscmd dns-dc-hostname /RecordAdd domainname.org www A 10.0.0.123</div></div>
<p>As you may have guessed this is the typical scenario where you&#8217;ve got to re-create some external zones, on the internal DNS servers. That&#8217;s needed in order for the internal hosts to reach some server with the &#8220;public&#8221; DNS name, but the private IP.<br />
For the sake of completeness, let me also mention that you could achieve the same effect by leaving DNS as it is, and configuring  &#8220;loopback NAT&#8221;/&#8221;double NAT&#8221; on the router/firewall. E.g.: an internal Host wants to reach an internal Server, given it&#8217;s public hostname, mapped to a public IP address. It asks the (possibly internal) DNS to translate the name. DNS doesn&#8217;t know the zone, it forwards the query to an external DNS Server, obtaining a public IP address that it hands back to the Client. Since its address is non-local, while trying to talk with the Server, the Client sends packets to its default gateway (possibly the router/firewall). The firewall matches the server&#8217;s public IP addresses, substituting it with the right private one. It also changes the source IP, swapping the Client&#8217;s with the firewall&#8217;s LAN address. This way Client and Server are actually communicating <i>through</i> the firewall, even if they&#8217;re both internal hosts. And the Server can&#8217;t tell Client A from Client B since every connection to it comes from the firewall&#8217;s IP address. That&#8217;s the main reason why I prefer duplicating the public DNS zones on internal DNS servers, with private IP addresses: you avoid routing internal traffic through the firewall, and avoid NAT where there shouldn&#8217;t be any.</p>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=486" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/uncategorized/using-the-cli-to-manage-windows-dns-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bulk unlocking Active Directory user accounts</title>
		<link>http://www.108.bz/posts/it/bulk-unlocking-active-directory-user-accounts/</link>
		<comments>http://www.108.bz/posts/it/bulk-unlocking-active-directory-user-accounts/#comments</comments>
		<pubDate>Sat, 15 May 2010 22:23:59 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=475</guid>
		<description><![CDATA[This post will show you how to generate a list of all the users&#8217; Distinguished Name, then filter it, then do something useful with it. Scenario: saturday morning (after having crashed into bed at 4:00 a.m., btw), Customer calls. A virus hit the Company and one of the most annoying consequences of the outburst, is [...]]]></description>
			<content:encoded><![CDATA[<p>This post will show you how to generate a list of all the users&#8217; <a href="http://en.wikipedia.org/wiki/Distinguished_Name">Distinguished Name</a>, then filter it, then do something useful with it.</p>
<p>Scenario: saturday morning (after having crashed into bed at 4:00 a.m., btw), Customer calls. A virus hit the Company and one of the most annoying consequences of the outburst, is that every domain user account gets locked due to brute-force login attempts (as per the &#8220;Account Lockout Threshold&#8221; <a href="http://technet.microsoft.com/en-us/library/dd277400.aspx">policy</a>). While they run around cleaning PCs and fixing A/V installations<sup class='footnote'><a href='#fn-475-1' id='fnref-475-1'>1</a></sup>, I&#8217;m asked for a method to quickly unlock the accounts.</p>
<p>I tend to carry out these kind of tasks &#8220;the Unix way&#8221;, using the available DOS prompt commands and a bit of VBScript.</p>
<ul>
<li>Start off by calling LDIFDE:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ldifde -r &quot;(objectclass=user)&quot; -l sAMAccountName -m -f users.ldf</div></div>
<p><a href="http://support.microsoft.com/kb/237677">LDIFDE</a> exports/imports Active Directory data to/from properly formatted (<a href="http://en.wikipedia.org/wiki/LDIF">LDIF</a>) text files. I use it a lot. Ran as shown above, LDIFDE exports the objects of class &#8220;user&#8221; into a file named <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">users.ldf</span> . Of the many attributes an LDAP object bears, I tell LDIFDE to output just the &#8220;sAMAccountName&#8221; one. If I hadn&#8217;t specified any attribute, in the resulting file I&#8217;d have found duplicate DNs for the same user. That&#8217;s because of how the resulting LDIF file is described. Some A/D data is &#8220;incrementally&#8221; added to existing objects given their DN. I just picked sAMAccountName because every user has one and, also, to keep the file small.</li>
<li>Then:
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">findstr /I /b dn.*ou=service.users users.ldf &gt; service_users.txt<br />
findstr /I /b dn.*cn=users users.ldf &gt; normal_users.txt</div></div>
<p><a href="http://technet.microsoft.com/en-us/library/bb490907.aspx">findstr</a> is Microsoft&#8217;s &#8220;poor man version&#8221; of <a href="http://en.wikipedia.org/wiki/Grep">grep</a>, supporting a subset of the regular expression everyone has or should&#8217;ve come to love. Here I&#8217;m using it to extract Distinguished Names from the LDIF (only the ones that lie in a given Organizational Unit), and saving them to the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">*_users.txt</span> files. They will look like:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dn: CN=squidauth,OU=Service Users,DC=contoso,DC=com<br />
dn: CN=exchangebackup,OU=Service Users,DC=contoso,DC=com<br />
dn: CN=ldap,OU=Service Users,DC=contoso,DC=com<br />
dn: CN=batchcopy,OU=Service Users,DC=contoso,DC=com</div></div>
</li>
<li>Here&#8217;s the VBScript function to unlock an account given its DN:
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Sub</span> unlockuser(userDN)<br />
&nbsp; <span style="color: #000080;">Set</span> objUser = GetObject (<span style="color: #800000;">&quot;LDAP://&quot;</span> &amp; userDN)<br />
&nbsp; objUser.IsAccountLocked = <span style="color: #000080;">False</span><br />
&nbsp; objUser.SetInfo<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></div></div>
<p>We just need to transform findstr&#8217;s output, substituting the leading &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">dn: </span>&#8221; with &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlockuser</span>&#8221; and enclosing in double quotes what follows. At the top of the new, transformed, file, we&#8217;ll copy/paste <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlockuser</span> subroutine definition. That&#8217;ll make our final script.</li>
<li>How to carry out the transform? Using this VBS snippet; it processes its <a href="http://en.wikipedia.org/wiki/Standard_input">Standard Input</a> line by line, and outputs the modifications on Standard Output, just like any Unix file filtering command.
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Set</span> StdIn = WScript.StdIn <br />
<span style="color: #000080;">Do</span> <span style="color: #000080;">While</span> <span style="color: #000080;">Not</span> StdIn.AtEndOfStream <br />
&nbsp; &nbsp; <span style="color: #000080;">line</span> = stdin.readline<br />
&nbsp; &nbsp; <span style="color: #000080;">line</span> = right(<span style="color: #000080;">line</span>,len(<span style="color: #000080;">line</span>)-4)<br />
&nbsp; &nbsp; wscript.echo <span style="color: #800000;">&quot;unlockuser &quot;</span><span style="color: #800000;">&quot;&quot;</span> &amp; <span style="color: #000080;">line</span> &amp; <span style="color: #800000;">&quot;&quot;</span><span style="color: #800000;">&quot;&quot;</span><br />
<span style="color: #000080;">Loop</span></div></div>
<p>I saved it in a &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">dnfilter.vbs</span>&#8221; file and used it this way:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">type service_users.txt | cscript /nologo dnfilter.vbs &gt; unlock_service_users.vbs</div></div>
<p>To obtain something like this:</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">unlockuser <span style="color: #800000;">&quot;CN=squidauth,OU=Service Users,DC=contoso,DC=com&quot;</span><br />
unlockuser <span style="color: #800000;">&quot;CN=exchangebackup,OU=Service Users,DC=contoso,DC=com&quot;</span><br />
unlockuser <span style="color: #800000;">&quot;CN=ldap,OU=Service Users,DC=contoso,DC=com&quot;</span><br />
unlockuser <span style="color: #800000;">&quot;CN=batchcopy,OU=Service Users,DC=contoso,DC=com&quot;</span></div></div>
</li>
</ul>
<p>As I said, add the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlockuser</span> function at the top of <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlock_service_users.vbs</span> and you&#8217;ll have your bulk unlocking script.
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-475-1'>A/V usefulness is often questionable. At least three times a year an unfortunate Customer gets infected by a 0-day threat&#8230; <img src='http://www.108.bz/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  <span class='footnotereverse'><a href='#fnref-475-1'>&#8617;</a></span></li>
</ol>
</div>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=475" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/bulk-unlocking-active-directory-user-accounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dumping streaming media in 25 lines of Perl</title>
		<link>http://www.108.bz/posts/it/dumping-streaming-media-in-25-lines-of-perl/</link>
		<comments>http://www.108.bz/posts/it/dumping-streaming-media-in-25-lines-of-perl/#comments</comments>
		<pubDate>Thu, 13 May 2010 10:11:23 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Network Protocol Analysis]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Reverse Engineering]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=459</guid>
		<description><![CDATA[Analysing TCP based protocols often means dealing with TCP sessions (also called streams or flows). A TCP connection, from an application point of view, is much like a bidirectional file descriptor through which ordered data can be read or written. &#8220;On the wire&#8221; though, data is not ordered at all. It is split into packets, [...]]]></description>
			<content:encoded><![CDATA[<p>Analysing TCP based protocols often means dealing with TCP <i>sessions</i> (also called streams or flows).<br />
A TCP connection, from an application point of view, is much like a bidirectional file descriptor through which ordered data can be read or written. &#8220;On the wire&#8221; though, data is not ordered at all. It is split into packets, possibly shuffled and mixed with other traffic. You can capture packets using a sniffer, but to make any sense of them you also need an analyzer tool able to do the reordering/reassembling job. <a href="http://www.wireshark.org">Wireshark</a>, for instance, doubles as a sniffer and an analyzer, backed up by the ubiquitous <a href="http://en.wikipedia.org/wiki/Libpcap">libpcap</a>.</p>
<p>Imagine having dumped/sniffed 1GB worth of traffic. We would like to pinpoint a single TCP session, isolating it from the rest. Here&#8217;s how we could proceed:</p>
<ul>
<li>Identify the source/destination addresses and source/destination ports we&#8217;re interested in. Then throw away any packet that doesn&#8217;t match this tuple. That&#8217;s what Wireshark basically does when you select a packet, right click and hit &#8220;Follow TCP Stream&#8221;. If the same tuple doesn&#8217;t get reused for another, unrelated, session, this method works just fine<sup class='footnote'><a href='#fn-459-1' id='fnref-459-1'>1</a></sup>.</li>
<li>Reorder/reassemble packets.</li>
<li>Extract packets&#8217; payload.</li>
<li>Present the payload in a way that makes sense. That depends on the L7 protocol. HTTP without <a href="http://en.wikipedia.org/wiki/HTTP_persistent_connection">keep-alive</a> is strictly request/response: print what the client sent to the server (outbound traffic) before and then what the server answered (inbound traffic). Other protocols may behave differently and you may choose to separate inbound traffic from outbound, or rely on timing to correctly present the dialogue between peers.</li>
</ul>
<p>Besides Wireshark, there are tools that do just that and can also be automated. See <a href="http://www.wireshark.org/docs/man-pages/tshark.html">TShark</a> or <a href="http://www.circlemud.org/~jelson/software/tcpflow/">tcpflow</a>.</p>
<p>What if you want to script everything and build your own TCP analyzer? Perl&#8217;s module <a href="http://search.cpan.org/search?query=Net%3A%3AAnalysis&#038;mode=module">Net::Analysis</a> is surprisingly convenient for the task. It does the dirty job I described above and presents your code with ready to be processed TCP sessions.</p>
<p>Practical goal: saving MP3 files streamed by <a href="http://grooveshark.com">Grooveshark</a>. Disclaimer: I&#8217;m by no means pushing anyone to illegally download stuff, this is just a working, sensible, instructional example that uses a song freely available anyway (by Revolution Void, check them out <a href="http://www.jamendo.com/en/artist/revolutionvoid/">here</a>, they&#8217;re great).</p>
<p><span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">GroovesharkListener.pm</span> extends <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">Net::Analysis::Listener::HTTP</span>. It sniffs all the traffic from/to port 80 and, as soon as he sees an HTTP response with a content-type of &#8220;audio&#8221;, dumps its content to file and quits. Simple as that.</p>
<p>Put the module some place where Perl can find it and then launch (as root):</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># perl -MNet::Analysis -e main GroovesharkListener 'port 80'<br />
(starting live capture)<br />
/crossdomain.xml<br />
text/xml<br />
/service.php?addSongsToQueueExt<br />
text/html; charset=UTF-8<br />
/static/amazonart/m8c8c9f4291508bca130c1caac2bda75b.png<br />
image/png<br />
[...some more cruft...]<br />
/stream.php<br />
audio/mpeg<br />
Dumping 8481224 bytes to groovesharkgyzBy.mp3 be patient...<br />
<br />
# id3v2 -l groovesharkgyzBy.mp3<br />
id3v1 tag info for groovesharkgyzBy.mp3:<br />
Title &nbsp;: Invisible Walls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Artist: Revolution Void &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Album &nbsp;: Increase the Dosage &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Year: 2004, Genre: Other (12)<br />
Comment: http://www.jamendo.com/ &nbsp; &nbsp; &nbsp; &nbsp; Track: 1</div></div>
<p>That&#8217;s it, just one more thing. <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">Net::Analysis</span> doesn&#8217;t allow you to select a specific network interface, it just picks up the first available one. I wrote a small <a href='http://www.108.bz/wp-content/uploads/2010/05/NetAnalysis_device_support_in_live_capture.diff_.txt'>patch</a> to address this shortcoming, it adds a &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">device=</span>&#8221; parameter that you can use this way:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># perl -MNet::Analysis -e main GroovesharkListener,device=wlan1 'port 80'</div></div>
<p>And here&#8217;s what <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">GroovesharkListener.pm</span> looks like:</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;height:300px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># choose a song</span><br />
<span style="color: #666666; font-style: italic;"># run (as root or via sudo):</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; perl -MNet::Analysis -e main GroovesharkListener 'port 80'</span><br />
<span style="color: #666666; font-style: italic;"># click &quot;play&quot; and wait for the file to be dumped...</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Giuliano - http://www.108.bz</span><br />
<a href="http://perldoc.perl.org/functions/package.html"><span style="color: #000066;">package</span></a> Net<span style="color: #339933;">::</span><span style="color: #006600;">Analysis</span><span style="color: #339933;">::</span><span style="color: #006600;">Listener</span><span style="color: #339933;">::</span><span style="color: #006600;">GroovesharkListener</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> base <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span>Net<span style="color: #339933;">::</span><span style="color: #006600;">Analysis</span><span style="color: #339933;">::</span><span style="color: #006600;">Listener</span><span style="color: #339933;">::</span><span style="color: #006600;">HTTP</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Temp</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">sub</span> http_transaction <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$http_req</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>req<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$http_resp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>resp<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <br />
<br />
&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$http_req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">uri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$content_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$http_resp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Content-Type'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;$content_type<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$content_type</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/audio/i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fh</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Temp</span><span style="color: #009900;">&#40;</span>TEMPLATE <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'groovesharkXXXXX'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SUFFIX &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'.mp3'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNLINK &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Dumping &quot;</span><span style="color: #339933;">.</span><a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$http_resp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot; bytes to &quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$fh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">filename</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot; be patient...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$fh</span> <span style="color: #0000ff;">$http_resp</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">content</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div></div>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-459-1'>newer Wireshark(s) use the &#8220;tcp.stream eq <i>x</i>&#8221; primitive <span class='footnotereverse'><a href='#fnref-459-1'>&#8617;</a></span></li>
</ol>
</div>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=459" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/dumping-streaming-media-in-25-lines-of-perl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Active Directory Graphs</title>
		<link>http://www.108.bz/posts/it/active-directory-graphs/</link>
		<comments>http://www.108.bz/posts/it/active-directory-graphs/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 15:26:32 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[VBS]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=443</guid>
		<description><![CDATA[Domain Controllers replicate Active Directory data with each other. They do so through Connections that are partly generated by the KCC (Knowledge Consistency Checker), partly configured by you: the Sysadmin . Each connection is one-way. If you open Active Directory Sites and Services, expand a Site and then a Server node, you&#8217;ll notice that Connections [...]]]></description>
			<content:encoded><![CDATA[<p>Domain Controllers replicate Active Directory data with each other. They do so through <i>Connections</i> that are partly generated by the <i>KCC</i> (Knowledge Consistency Checker), partly configured by you: the Sysadmin . Each connection is one-way. If you open <i>Active Directory Sites and Services</i>, expand a Site and then a Server node, you&#8217;ll notice that Connections listed under <i>NTDS Settings</i> are labeled &#8220;From Server&#8221; and &#8220;From Site&#8221;. In the image below (stolen from <a href="http://technet.microsoft.com/en-us/library/dd277430.aspx">here</a>), the DC named HEIDITEST will replicate AD changes by sending them <i>to</i> MHILLMAN2. The Connection Object is thus defined <i>from</i> HEIDITEST, <i>to</i> MHILLMAN2. You can expect a specular Connection to exist, defined under the <i>NTDS Settings</i> node of HEIDITEST.<br />
<a href="http://www.108.bz/wp-content/uploads/2010/04/adss.gif"><img src="http://www.108.bz/wp-content/uploads/2010/04/adss-300x135.gif" alt="" title="Active Directory Sites and Services" width="300" height="135" class="alignnone size-medium wp-image-452" /></a><br />
See <a href="http://technet.microsoft.com/en-us/library/dd277429.aspx">Active Directory Replication</a> for a more in-depth explanation.<br />
Besides Connection objects automatically created by the <i>KCC</i>, which does its best to build a proper replication topology, you sometimes add your own for fault/link tolerance or other reasons. If the domain is sufficiently big, things may become messy. Instead of fumbling my way through <i>Active Directory Sites and Services</i> I wanted to automatically generate a visual representation of such topology, with DCs and Connections: time to write yet another script. </p>
<p>This time I chose VBS over Perl, hoping that this post would be more &#8220;instructional&#8221;. Perl on Windows is not so common, while VBScript is the standard way to automate stuff on that O.S. (despite the language being incredibly clumsy and annoying<sup class='footnote'><a href='#fn-443-1' id='fnref-443-1'>1</a></sup>).</p>
<p>As for the graph format, I chose to output <a href="http://www.graphviz.org/">Graphviz</a> <a href="http://www.graphviz.org/doc/info/lang.html">DOT</a> format/language.</p>
<p>The script works this way:</p>
<ul>
<li>Find the current domain.</li>
<li>Find all the Domain Controllers (AD objects of class <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">nTDSDSA</span>, see <a href="http://blogs.technet.com/heyscriptingguy/archive/2004/12/16/how-can-i-get-a-list-of-all-the-domain-controllers-in-my-domain.aspx">this</a>) and the <i>Site</i> they&#8217;re in.</li>
<li>For each DC/Site, select <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">nTDSConnection</span> objects in <i>NTDS Settings</i>. Of course this is done by means of LDAP queries over <a href="http://en.wikipedia.org/wiki/ActiveX_Data_Objects">ADO</a>, but the view we get is equivalent to what we&#8217;re seeing in <i>Active Directory Sites and Services</i>.</li>
<li>Print the DOT graph on standard output: DCs, connections and sites. DCs in the same site will be clustered together.</li>
</ul>
<p>To use it, first generate the graph&#8217;s definition:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cscript /nologo ntdsconnections_graph.vbs &gt; AD-pre.dot</div></div>
<p>Then use Graphviz&#8217;s tools to lay out the graph and turn it into an actual image. For optimal results, I suggest something like:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ccomps -x AD-pre.dot | dot | gvpack -u | neato -Tpng -n2 &gt; AD-pre.png</div></div>
<p>Here&#8217;s what showed up, in my test case:<br />
<a href="http://www.108.bz/wp-content/uploads/2010/04/AD-pre.png"><img src="http://www.108.bz/wp-content/uploads/2010/04/AD-pre-300x160.png" alt="" title="AD-pre" width="300" height="160" class="alignnone size-medium wp-image-454" /></a></p>
<p>And here&#8217;s the same Domain, after some treatment:<br />
<a href="http://www.108.bz/wp-content/uploads/2010/04/AD-post.png"><img src="http://www.108.bz/wp-content/uploads/2010/04/AD-post-300x104.png" alt="" title="AD-post" width="300" height="104" class="alignnone size-medium wp-image-455" /></a><br />
Such graphs may be useful from a Sysadmin point of view, but they&#8217;re quite ugly, honestly. I originally thought to use Graphviz to output &#8220;some&#8221; format, read it in <a href="http://projects.gnome.org/dia/">Dia</a> or similar diagram drawing software, and then fix the aesthetics. But Dia support (if it ever worked) has been dropped from Grapviz (<a href="http://www.graphviz.org/cvs/ChangeLog">December 10, 2009</a>). Dia&#8217;s 0.97.1 tarball bears a &#8220;dot2dia.py&#8221; plugin, but I haven&#8217;t hacked it into working. Any other editable format known to Graphviz (e.g.: SVG) doesn&#8217;t support &#8220;connector&#8221; primitives meaning that arrows won&#8217;t stick to objects while you drag them around&#8230; I&#8217;ll follow up if I make some progress.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;height:300px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">' A/D replication topology graph (Graphviz .DOT format)<br />
</span><span style="color: #008000;">' in the current Domain.<br />
</span><span style="color: #008000;">' ----------------------------<br />
</span><span style="color: #008000;">' Giuliano - http://www.108.bz<br />
</span><br />
<span style="color: #000080;">Set</span> objRootDSE = GetObject(<span style="color: #800000;">&quot;LDAP://RootDSE&quot;</span>)<br />
strConfigurationNC = objRootDSE.<span style="color: #000080;">Get</span>(<span style="color: #800000;">&quot;configurationNamingContext&quot;</span>)<br />
<br />
<span style="color: #000080;">Set</span> adoCommand = CreateObject(<span style="color: #800000;">&quot;ADODB.Command&quot;</span>)<br />
<span style="color: #000080;">Set</span> adoConnection = CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)<br />
adoConnection.Provider = <span style="color: #800000;">&quot;ADsDSOObject&quot;</span><br />
adoConnection.<span style="color: #000080;">Open</span> <span style="color: #800000;">&quot;Active Directory Provider&quot;</span><br />
adoCommand.ActiveConnection = adoConnection<br />
<br />
strBase = <span style="color: #800000;">&quot;&lt;LDAP://&quot;</span> &amp; strConfigurationNC &amp; <span style="color: #800000;">&quot;&gt;&quot;</span><br />
strFilter = <span style="color: #800000;">&quot;(objectClass=nTDSDSA)&quot;</span><br />
strAttributes = <span style="color: #800000;">&quot;AdsPath&quot;</span><br />
strQuery = strBase &amp; <span style="color: #800000;">&quot;;&quot;</span> &amp; strFilter &amp; <span style="color: #800000;">&quot;;&quot;</span> &amp; strAttributes &amp; <span style="color: #800000;">&quot;;subtree&quot;</span><br />
<br />
adoCommand.CommandText = strQuery<br />
adoCommand.Properties(<span style="color: #800000;">&quot;Page Size&quot;</span>) = 100<br />
adoCommand.Properties(<span style="color: #800000;">&quot;Timeout&quot;</span>) = 60<br />
adoCommand.Properties(<span style="color: #800000;">&quot;Cache Results&quot;</span>) = <span style="color: #000080;">False</span><br />
<br />
<span style="color: #000080;">Set</span> adoRecordset = adoCommand.Execute<br />
<br />
<span style="color: #000080;">Dim</span> dictDCtoSite<br />
<span style="color: #000080;">Set</span> dictDCtoSite = CreateObject(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)<br />
<span style="color: #000080;">Dim</span> dictSites<br />
<span style="color: #000080;">Set</span> dictSites = CreateObject(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)<br />
<span style="color: #000080;">Dim</span> arrLink()<br />
<br />
<span style="color: #000080;">Function</span> pp(s)<br />
&nbsp; &nbsp; pp = Replace(right(s,len(s)-3), <span style="color: #800000;">&quot;-&quot;</span>, <span style="color: #800000;">&quot;_&quot;</span>) <span style="color: #008000;">' trash the leading &quot;CN=&quot;<br />
</span><span style="color: #000080;">End</span> <span style="color: #000080;">Function</span><br />
<br />
<span style="color: #000080;">Do</span> <span style="color: #000080;">Until</span> adoRecordset.EOF<br />
&nbsp; &nbsp; <span style="color: #000080;">Set</span> objDC = _<br />
&nbsp; &nbsp; &nbsp; &nbsp; GetObject(GetObject(adoRecordset.Fields(<span style="color: #800000;">&quot;AdsPath&quot;</span>).Value).Parent)<br />
&nbsp; &nbsp; <span style="color: #000080;">Set</span> objSite = _<br />
&nbsp; &nbsp; &nbsp; &nbsp; GetObject(GetObject(objDC.Parent).Parent)<br />
&nbsp; &nbsp; dictDCtoSite.Add objDC.name, objSite.name<br />
&nbsp; &nbsp; <span style="color: #000080;">if</span> <span style="color: #000080;">not</span> dictSites.Exists(objSite.name) <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dictSites.Add objSite.name, 1<br />
&nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
&nbsp; &nbsp; adoRecordset.MoveNext<br />
<span style="color: #000080;">Loop</span><br />
adoRecordset.<span style="color: #000080;">Close</span><br />
<br />
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> strDcRDN <span style="color: #000080;">in</span> dictDCtoSite.Keys <br />
&nbsp; &nbsp; strSiteRDN = dictDCtoSite.Item(strDcRDN)<br />
<br />
&nbsp; &nbsp; strNtdsSettingsPath = <span style="color: #800000;">&quot;LDAP://cn=NTDS Settings,&quot;</span> &amp; strDcRDN &amp; _<br />
&nbsp; &nbsp; <span style="color: #800000;">&quot;,cn=Servers,&quot;</span> &amp; strSiteRDN &amp; <span style="color: #800000;">&quot;,cn=Sites,&quot;</span> &amp; strConfigurationNC<br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">Set</span> objNtdsSettings = GetObject(strNtdsSettingsPath)<br />
<br />
&nbsp; &nbsp; objNtdsSettings.Filter = Array(<span style="color: #800000;">&quot;nTDSConnection&quot;</span>)<br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objConnection <span style="color: #000080;">In</span> objNtdsSettings<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">'WScript.Echo strSiteRDN &amp; &quot; : &quot; &amp; Split(objConnection.fromServer, &quot;,&quot;)(1) &amp; &quot; -&gt; &quot; &amp; strDcRDN <br />
</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrLink(2,k)<br />
&nbsp; &nbsp; &nbsp; &nbsp; arrLink(0,k) = strSiteRDN<br />
&nbsp; &nbsp; &nbsp; &nbsp; arrLink(1,k) = Split(objConnection.fromServer, <span style="color: #800000;">&quot;,&quot;</span>)(1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; arrLink(2,k) = strDcRDN<br />
&nbsp; &nbsp; &nbsp; &nbsp; k = k + 1<br />
&nbsp; &nbsp; <span style="color: #000080;">Next</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">Set</span> strNtdsSettingsPath = <span style="color: #000080;">Nothing</span><br />
<span style="color: #000080;">Next</span><br />
<br />
<span style="color: #000080;">Dim</span> arrSubgraphs()<br />
<span style="color: #000080;">Redim</span> arrSubgraphs(dictSites.Count-1)<br />
<br />
WScript.Echo <span style="color: #800000;">&quot;Digraph AD {&quot;</span><br />
WScript.Echo <span style="color: #800000;">&quot; &nbsp;fontname=helvetica;&quot;</span><br />
WScript.Echo <span style="color: #800000;">&quot; &nbsp;node [fontname=helvetica];&quot;</span><br />
<span style="color: #008000;">' Same site links<br />
</span><span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> strSiteRDN <span style="color: #000080;">in</span> dictSites<br />
&nbsp; &nbsp; nosamesitelinks = <span style="color: #000080;">True</span><br />
&nbsp; &nbsp; headerwritten = <span style="color: #000080;">False</span><br />
&nbsp; &nbsp; <span style="color: #000080;">For</span> k = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">Ubound</span>(arrLink, 2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">If</span> strSiteRDN = arrLink(0,k) <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">if</span> dictDCtoSite.Item(arrLink(1,k)) = dictDCtoSite.Item(arrLink(2,k)) <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">if</span> nosamesitelinks <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nosamesitelinks = <span style="color: #000080;">False</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo <span style="color: #800000;">&quot; &nbsp; &nbsp;subgraph cluster_&quot;</span> &amp; pp(strSiteRDN) &amp; <span style="color: #800000;">&quot; {&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; headerwritten = <span style="color: #000080;">True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo <span style="color: #800000;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;&quot;</span> &amp; pp(arrLink(1,k)) &amp; <span style="color: #800000;">&quot; -&gt; &quot;</span> &amp; pp(arrLink(2,k)) &amp; <span style="color: #800000;">&quot;;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Next</span><br />
&nbsp; &nbsp; <span style="color: #000080;">If</span> headerwritten <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo <span style="color: #800000;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;label= &quot;</span><span style="color: #800000;">&quot;&quot;</span> &amp; pp(strSiteRDN) &amp; <span style="color: #800000;">&quot;&quot;</span><span style="color: #800000;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo <span style="color: #800000;">&quot; &nbsp; &nbsp;}&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<span style="color: #000080;">Next</span><br />
Wscript.Echo<br />
<span style="color: #008000;">' Inter-site links<br />
</span><span style="color: #000080;">For</span> k = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">Ubound</span>(arrLink, 2)<br />
&nbsp; &nbsp; <span style="color: #000080;">if</span> dictDCtoSite.Item(arrLink(1,k)) &lt;&gt; dictDCtoSite.Item(arrLink(2,k)) <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo <span style="color: #800000;">&quot; &nbsp; &nbsp;&quot;</span> &amp; pp(arrLink(1,k)) &amp; <span style="color: #800000;">&quot; -&gt; &quot;</span> &amp; pp(arrLink(2,k)) &amp; <span style="color: #800000;">&quot;;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<span style="color: #000080;">Next</span><br />
WScript.Echo <span style="color: #800000;">&quot;}&quot;</span></div></div>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-443-1'>No powerful and convenient data types, no free and ready to use debugger, no public CPAN-like module repository, unnecessarily verbose syntax; I may go on for an hour&#8230; <span class='footnotereverse'><a href='#fnref-443-1'>&#8617;</a></span></li>
</ol>
</div>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=443" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/active-directory-graphs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Allot NetEnforcer bandwidth reports</title>
		<link>http://www.108.bz/posts/it/allot-netenforcer-bandwidth-reports/</link>
		<comments>http://www.108.bz/posts/it/allot-netenforcer-bandwidth-reports/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 14:01:20 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Allot]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Performance Monitoring]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=429</guid>
		<description><![CDATA[A while ago I was trying to get my head around some nasty network performance issues. A couple of firewalls were in the play, along with a Bandwidth Manager device (an Allot NetEnforcer AC-402). I wasn&#8217;t completely satisfied with NetEnforcer reporting functions and wanted something more dependable and realtime. Well, if you turn to the [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I was trying to get my head around some nasty network performance issues. A couple of firewalls were in the play, along with a Bandwidth Manager device (an <a href="http://www.allot.com/NetEnforcer_AC-400.html">Allot NetEnforcer AC-402</a>).</p>
<p>I wasn&#8217;t completely satisfied with NetEnforcer reporting functions and wanted something more dependable and realtime. Well, if you turn to the device&#8217;s CLI access (SSH), you&#8217;ll notice an interesting <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">acthruput</span> command.<br />
It shows the <i>current</i> throughput per Interface, Line, Pipe and Virtual Channel. What more could you ask for?</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">AC:~# acthruput<br />
---------------------------------------------------------<br />
Entity &nbsp; &nbsp; &nbsp; &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bits/sec<br />
---------------------------------------------------------<br />
INTERFACE &nbsp; &nbsp; &nbsp;Internal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1918600<br />
&nbsp; LINE &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1770720<br />
&nbsp; &nbsp; &nbsp; PIPE &nbsp; &nbsp; 8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2144<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VC &nbsp; 32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2144<br />
&nbsp; &nbsp; &nbsp; PIPE &nbsp; &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7136<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VC &nbsp; 8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7136<br />
[..]<br />
---------------------------------------------------------<br />
INTERFACE &nbsp; &nbsp; &nbsp;External &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9509880<br />
&nbsp; LINE &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9421000<br />
&nbsp; &nbsp; &nbsp; PIPE &nbsp; &nbsp; 8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;96960<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VC &nbsp; 32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 96960<br />
&nbsp; &nbsp; &nbsp; PIPE &nbsp; &nbsp; 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 752<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VC &nbsp; 22 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 752<br />
[..]</div></div>
<p>As you can see, <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">acthruput</span> identifies Pipes by number. How do you relate this number to the actual mnemonic pipe name? Use &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">acstat -l pipe</span>&#8220;, which also displays the total number of live connections per pipe .</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">AC:~# acstat -l pipe<br />
---------------------------------------------------------------------------------<br />
Rule QID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Rule name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Live connections<br />
---------------------------------------------------------------------------------<br />
1.8.0.0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Customer1 ; Fallback &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10<br />
1.13.0.0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Customer2 ; Fallback &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7<br />
1.5.0.0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Customer3 ; Fallback &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 23<br />
[..]</div></div>
<p>Wrap <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">acthruput</span> in a <i>while</i> loop that adds a timestamp and a delay (&rarr; sampling frequency). Start your terminal emulator logging facilities, hit enter, wait, ctrl-c, stop logging.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">AC:~# while [ 1 ] ; do date; acthruput; sleep 10; done</div></div>
<p>Eventually, clean the log a bit and feed it to the Perl script you&#8217;ll find at the end of this post.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ DATE='Thu Dec 10'; grep &quot;$DATE\|INTERFACE\|LINE\|PIPE&quot; &quot;log.txt&quot; &nbsp;| ./allot_fmt.pl &quot;$DATE&quot; &gt; log.csv</div></div>
<p>The script outputs CSV formatted data:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">timestamp;ifc;L1;P1;P10;P12;P2;P3;P4;P5;P8;P9;<br />
Thu Dec 10 14:48:00 CET 2009;Int;2779648;2599928;4608;;111760;1024;;9792;;52536;<br />
Thu Dec 10 14:48:00 CET 2009;Ext;8372424;5372392;206448;;2407264;60720;;258816;;66784;<br />
Thu Dec 10 14:48:12 CET 2009;Int;1909272;1699872;3776;;170624;512;;1216;;33272;<br />
Thu Dec 10 14:48:12 CET 2009;Ext;7932680;7370584;97152;;350920;36432;;12144;;65448;<br />
[..]</div></div>
<p>And here&#8217;s what it looks like when opened up in OpenOffice Calc (sorry, no fancy formatting).<br />
<a href="http://www.108.bz/wp-content/uploads/2010/04/Allot_NetEnforcer_bandwidth_reports.gif"><img src="http://www.108.bz/wp-content/uploads/2010/04/Allot_NetEnforcer_bandwidth_reports-300x181.gif" alt="NetEnforcer bandwidth report" title="NetEnforcer_bandwidth_report" width="300" height="181" class="alignnone size-medium wp-image-435" /></a><br />
The graph above shows that the 8Mbps link (the &#8220;Line&#8221;, in Allot&#8217;s parlance) is not saturated. Problem was that, during that timeframe, we were also trying to make <a href="http://en.wikipedia.org/wiki/Iperf">Iperf</a> &#8220;consume&#8221; all of the available bandwidth. We couldn&#8217;t make it because one of the firewalls was acting as a bottleneck if presented with certain workloads (many connections, see <a href="http://www.108.bz/posts/it/who-ate-all-the-bandwidth/">this</a>) . Being able to generate these kinds of report proved very useful in troubleshooting&#8230;</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;height:300px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl </span><br />
<span style="color: #666666; font-style: italic;"># Giuliano - http://www.108.bz</span><br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@samples</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lastsample</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lastint</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009966; font-style: italic;">s/[\r\n]*//g</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">next</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/$ARGV[0]/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$lastsample</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$lastsample</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$lastsample</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@samples</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$lastsample</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#print &quot;$_\n&quot;;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/INTERFACE/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">s/^.*INTERFACE.*(Int|Ext)ernal.*$/$1/</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$lastint</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#print &quot;$lastint\n&quot;;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/LINE/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">s/^.*LINE\s*([0-9]+)\s*(\d+).*$/L$1;$2/</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$line</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$tput</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a> <span style="color: #ff0000;">';'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#print &quot;$line,$tput\n&quot;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$lastsample</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$lastint</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$line</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$tput</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/PIPE/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">s/^.*PIPE\s*([0-9]+)\s*(\d+).*$/P$1;$2/</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$pipe</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$tput</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a> <span style="color: #ff0000;">';'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#print &quot;$pipe,$tput\n&quot;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$lastsample</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$lastint</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$pipe</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$tput</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #000000; font-weight: bold;">STDERR</span> <span style="color: #ff0000;">&quot;wtf<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sample</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@samples</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$int</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/keys.html"><span style="color: #000066;">keys</span></a> <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$sample</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$key</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/keys.html"><span style="color: #000066;">keys</span></a> <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$sample</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$int</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$keys</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$key</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #339933;">@</span><a href="http://perldoc.perl.org/functions/keys.html"><span style="color: #000066;">keys</span></a> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/sort.html"><span style="color: #000066;">sort</span></a> <a href="http://perldoc.perl.org/functions/keys.html"><span style="color: #000066;">keys</span></a> <span style="color: #0000ff;">%$keys</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;timestamp;ifc;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$key</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><a href="http://perldoc.perl.org/functions/keys.html"><span style="color: #000066;">keys</span></a><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;$key;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sample</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@samples</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$int</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Int'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'Ext'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;$sample-&gt;[0];&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;$int;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$key</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><a href="http://perldoc.perl.org/functions/keys.html"><span style="color: #000066;">keys</span></a><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;$sample-&gt;[1]-&gt;{$int}-&gt;{$key};&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #339933;">;</span></div></div>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=429" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/allot-netenforcer-bandwidth-reports/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Conditional address rewriting with Postfix</title>
		<link>http://www.108.bz/posts/it/conditional-address-rewriting-with-postfix/</link>
		<comments>http://www.108.bz/posts/it/conditional-address-rewriting-with-postfix/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 20:35:49 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Postfix]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=416</guid>
		<description><![CDATA[Today I had the need to (automatically) rewrite sender addresses of an email depending on the recipient domain. A way to trick Postfix into applying a sort of &#8220;conditional masquerading&#8221;. Postfix rewriting tables are just static key &#8594; value dictionaries: they&#8217;re used to lookup B given A, but there&#8217;s no available logic to cope with [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had the need to (automatically) rewrite <i>sender</i> addresses of an email depending on the <i>recipient</i> domain. A way to trick Postfix into applying a sort of &#8220;conditional masquerading&#8221;. Postfix rewriting tables are just static key &rarr; value dictionaries: they&#8217;re used to lookup B given A, but there&#8217;s no available logic to cope with more complicated patterns.<br />
A little more context to help me explain: I&#8217;m talking about a monitoring system. Alert emails are generated by Nagios and handed to a local Postfix on the same server. And here are the rules to implement:</p>
<ul>
<li>A locally generated email whose destination is <i>inside</i> the company, should leave Postfix with a <i>@FQDN</i> suffix (<i>@hostname.localdomain.lan</i>) in its sender addresses. Sender addresses shouldn&#8217;t be rewritten/masqueraded at all.</li>
<li>A locally generated email whose destination is <i>outside</i> of the company, needs to be masquerated, its sender addresses rewritten as <i>@extdomain.com</i> .</li>
</ul>
<p>Moreover, but that&#8217;s a routing matter rather than a rewriting one:</p>
<ul>
<li>Emails directed to <i>@smsgw.localdomain.lan</i> have to be relayed through a different mail server. </li>
</ul>
<p>As you can see, the logic is: lookup B (rewritten sender) given A (sender) depending on C (recipient).</p>
<p>I found the right hint deeply <a href="http://thread.gmane.org/gmane.mail.postfix.user/125861/focus=125866">buried</a> in Postfix&#8217;s mailing list: check out Noel Jones post, kudos to him.</p>
<ul>
<li>First, define a new <i>smtp</i> transport in &#8220;master.cf&#8221;; just copy/paste the existing one and change the first column to whatever name you like. We are explicitly telling the new transport that it will use its own <a href="http://www.postfix.org/ADDRESS_REWRITING_README.html#generic">generic</a> <i>regexp</i> map (the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">-o</span> command-line option).</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@hostname postfix]# cd /etc/postfix<br />
[root@hostname postfix]# grep '^\(smtp\|toext\).*unix' master.cf <br />
smtp &nbsp; &nbsp; &nbsp;unix &nbsp;- &nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; &nbsp; n &nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; &nbsp; smtp<br />
toext &nbsp; &nbsp; unix &nbsp;- &nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; &nbsp; n &nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; &nbsp; smtp -o smtp_generic_maps=regexp:/etc/postfix/generic_toext</div></div>
</li>
<li>We also need to take control over the mail routing mechanism. This is done by enabling <a href="http://www.postfix.org/transport.5.html">transport</a> maps.
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@hostname postfix]# grep ^transport main.cf<br />
transport_maps = regexp:/etc/postfix/transport</div></div>
</li>
<li>Transport maps (remember that they&#8217;re matched against <i>From</i> addresses) are configured in order to:
<ul>
<li>Route mail that should be delivered locally through the <i>local</i> transport. This will preserve <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">/etc/aliases</span> and <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">.forward</span> behaviour and make everything act like you expect on Unix.</li>
<li>Route mail to @smsgw.localdomain.lan, via its dedicated gateway, using the &#8220;standard&#8221; <i>smtp</i> transport.</li>
<li>Route mail to @localdomain.lan, through the main SMTP gateway, using the <i>smtp</i> transport.</li>
<li>Route any other message through the main SMTP gateway, <i>but</i> use our custom transport.</li>
</ul>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@hostname postfix]# tail -4 transport<br />
/@hostname\.localdomain\.lan$/ &nbsp;local:hostname.localdomain.lan<br />
/@smsgw\.localdomain\.lan$/ &nbsp; &nbsp; smtp:[smsgw.localdomain.lan]<br />
/@localdomain\.lan/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; smtp:[gateway.localdomain.lan]<br />
/@.*$/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toext:[gateway.localdomain.lan]</div></div>
</li>
<li>The custom transport&#8217;s <i>generic</i> map rewrites recipient adresses, shortening the FQDN by preserving just the domain name, and changing the address part before the @ sign. Hostname is being stripped but I still want to be able to tell, at a glance, from where the message originates. When they leave the mail system, rewritten addresses look like <i>username</i>-<i>hostname</i>@<i>extdomain</i>.<i>com</i> .
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@hostname postfix]# cat generic_toext<br />
/^(.*)@hostname\.localdomain\.lan$/ $1-hostname@extdomain.com</div></div>
</li>
</ul>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=416" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/conditional-address-rewriting-with-postfix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Who ate all the bandwidth?</title>
		<link>http://www.108.bz/posts/it/who-ate-all-the-bandwidth/</link>
		<comments>http://www.108.bz/posts/it/who-ate-all-the-bandwidth/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 17:36:40 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Performance Monitoring]]></category>
		<category><![CDATA[Switching]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=370</guid>
		<description><![CDATA[Today Internet browsing is particularly slow. At seemingly random intervals, available bandwith drops down and people get more and more irritable. How do you find out why this is happening? The possible causes boil down to: Router/Firewall1 is not pleased by &#8220;something&#8221;. Could be an attack or a bug in the device firmware. Too many [...]]]></description>
			<content:encoded><![CDATA[<p>Today Internet browsing is particularly slow.<br />
At seemingly random intervals, available bandwith drops down and people get more and more irritable. <img src='http://www.108.bz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>How do you find out why this is happening?</p>
<p>The possible causes boil down to:</p>
<ol style="list-style-type: upper-alpha;">
<li style="list-style-type: upper-alpha;">Router/Firewall<sup class='footnote'><a href='#fn-370-1' id='fnref-370-1'>1</a></sup> is not pleased by &#8220;something&#8221;. Could be an attack or a bug in the device firmware.</li>
<li style="list-style-type: upper-alpha;">Too many connections. Maybe they&#8217;re not passing much traffic, but the internet gateway can&#8217;t keep up with their number. I&#8217;ve seen firewalls perform very badly in this respect. E.g.: 3 connections trying to download/upload as fast as they can, and a total, aggregate, b/w of 10Mbps. Those 3 plus 3000 &#8220;normal&#8221; connections and a total b/w of 6Mbps.</li>
<li style="list-style-type: upper-alpha;">A reasonable amount of connections, effectively eating all of the available bandwidth.</li>
</ol>
<p>I&#8217;ll skip case <b>A</b>, for now. <img src='http://www.108.bz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
In case <b>B</b> you&#8217;ll likely want to know the firewall&#8217;s idea of &#8220;netstat&#8221;, meaning the complete listing of TCP/UDP/other connections. No big deal if the device has got some sort of CLI access: capture its output, import it into a spreadsheet, or use awk/sort/grep<sup class='footnote'><a href='#fn-370-2' id='fnref-370-2'>2</a></sup> to build your stats. Usually, computing total number of connections by source IP address and sorting accordingly, is enough to gain some insight about what&#8217;s going on.<br />
Case <b>C</b>&#8230; For long-running (days) data analysis, you could use a tool like <a href="http://www.ntop.org/">NTOP</a>. But if, like me today, you need to act quickly (perhaps because you know that the issue will disappear soon), <a href="http://www.ex-parrot.com/pdw/iftop/">iftop</a> can hardly be beaten.<br />
Both tools require the machine they run on to be able to &#8220;sniff&#8221; all the traffic passing through the firewall. This can be accomplished by configuring <i>monitoring</i>/<i>monitored</i> port(s) on a switch.  <i>Monitored</i> ports get their inbound/outbound traffic copied to the monitoring one. Different vendors call the thing a different way, <i>port mirroring</i> is also a good keyphrase. Here are a couple of resources:</p>
<ul>
<li>(Old) 3Com Superstack: <a href="http://blog.icewolf.ch/archive/2008/07/08/monitor-port-on-3com-4400.aspx">Monitor Port on 3Com 4400</a></li>
<li>HP ProCurve, pretty straightforward to set up using the &#8220;menu&#8221; interface:  <a href="http://www.hp.com/rnd/support/faqs/sw_208_224.htm#question25">How do I attach a LAN Analyzer to a Switch 208t/224t port to monitor LAN traffic for diagnostic purposes?</a></li>
<li>ProCurve switches are not limited to mirroring ports that belong to the same device/chassis: <a href="http://pro-h40060-hpwpux-pro.atlanta.hp.com/procurve/uk/en/pdfs/application-notes/AN-S14_ProCurve-intelligent-mirroring-final.pdf">How to configure remote and intelligent mirroring on ProCurve switches</a></li>
<li>
Low-end HP switches (like the ProCurve 1800 one I encountered here), though, are only manageable via a web gui:<br />
<div id="attachment_389" class="wp-caption alignnone" style="width: 310px"><a href="http://www.108.bz/wp-content/uploads/2010/03/procurve1800mirroring.png"><img src="http://www.108.bz/wp-content/uploads/2010/03/procurve1800mirroring-300x120.png" alt="Port Mirroring on a ProCurve 1800" title="procurve1800mirroring" width="300" height="120" class="size-medium wp-image-389" /></a><p class="wp-caption-text">Port Mirroring on a ProCurve 1800</p></div>
</li>
<li>Cisco: <a href="http://en.wikipedia.org/wiki/Port_mirroring">Port Mirroring</a>, <a href="http://itprofesionals.blogspot.com/2009/12/configuring-cisco-catalyst-switch-span.html">Configuring a Cisco Catalyst Switch SPAN mirroring port</a>
</li>
</ul>
<p>(You could as well use a hub instead of a switch and get implicit mirroring of any port, to any port of the hub. Just unplug the firewall, link the hub to the switch, plug firewall and monitoring host in the hub. Kludgy but quick and easy, if you can afford the temporary cabling changes, and the bottleneck introduced by the hub&#8230;)</p>
<p>So:
<ul>
<li>Find the switch where the firewall is connected to. Which side of the firewall? It depends on where you believe the issues originates from. Let&#8217;s say the culprit is most likely to lie on the LAN &rarr; switch port A.</li>
<li>Connect your laptop/monitoring machine to the same switch &rarr; port B.</li>
<li>Set up monitoring: port A is <i>monitored</i>, port B is <i>monitoring</i>.</li>
<li>Run iftop, maybe telling it to also show port numbers (&#8220;-P&#8221;, without this switch, you&#8217;ll only see totals by source/destination IP addresses couple), don&#8217;t display hostnames &#8220;-n&#8221;, the interface &#8220;-i eth0&#8243; and provide a meaningful filter (here I&#8217;m selecting packets whose source is not on the LAN<sup class='footnote'><a href='#fn-370-3' id='fnref-370-3'>3</a></sup>. The &#8220;-p&#8221; option instructs iftop to capture packets in <a href="http://en.wikipedia.org/wiki/Promiscuous_mode">promiscuous</a> mode. Without it, iftop won&#8217;t lift off the wire packets that aren&#8217;t addressed to the machine on which it is running.
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iftop -p -P -n -i eth0 -f 'not src net 192.168.200.0/23'</div></div>
<p>Iftop will produce a realtime table of running connections, sorted by how demanding they are in terms of bandwidth (10s average, by default). See the screenshot below; the top connections are due to two running video conference streams stealing 1Mbit/second worth of bandwidth, each.<br />
<div id="attachment_394" class="wp-caption alignnone" style="width: 310px"><a href="http://www.108.bz/wp-content/uploads/2010/03/iftop.png"><img src="http://www.108.bz/wp-content/uploads/2010/03/iftop-300x193.png" alt="iftop output" title="iftop" width="300" height="193" class="size-medium wp-image-394" /></a><p class="wp-caption-text">iftop's output</p></div><br />
Once everything is set up and you&#8217;re able to read iftop&#8217;s output, spotting the &#8220;top talkers&#8221; of your net becomes kids play, enjoy!
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-370-1'>for brevity, I&#8217;ll just say &#8220;firewall&#8221; from now on. <span class='footnotereverse'><a href='#fnref-370-1'>&#8617;</a></span></li>
<li id='fn-370-2'>Yuri is king at doing that. See his <a href="http://yurisk.info/2010/03/08/awk-weekly-checkpoint-anti-spam-statistics-or-viva-la-open-relays/">AWK weekly</a> series. <span class='footnotereverse'><a href='#fnref-370-2'>&#8617;</a></span></li>
<li id='fn-370-3'>iftop will still show these source addresses, since its output is always made of bidirectional &#8220;connections&#8221;. Only, counters pertaining to the LAN &rarr; outside direction, won&#8217;t increase. <span class='footnotereverse'><a href='#fnref-370-3'>&#8617;</a></span></li>
</ol>
</div>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=370" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/who-ate-all-the-bandwidth/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
