<?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>Josh Erickson &#187; dump</title>
	<atom:link href="http://josherickson.org/category/dump/feed" rel="self" type="application/rss+xml" />
	<link>http://josherickson.org</link>
	<description>And as you tread the halls of sanity...</description>
	<lastBuildDate>Thu, 09 Sep 2010 17:35:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Wake-on-Lan (WOL) via Powershell</title>
		<link>http://josherickson.org/2010/05/07/785/wake-on-lan-wol-via-powershell</link>
		<comments>http://josherickson.org/2010/05/07/785/wake-on-lan-wol-via-powershell#comments</comments>
		<pubDate>Fri, 07 May 2010 18:36:23 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[concepts]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[wake-on-lan]]></category>
		<category><![CDATA[wol]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=785</guid>
		<description><![CDATA[Despite what others may say, Wake-on-LAN isn&#8217;t magic and isn&#8217;t that complicated a feat to do anymore. With Powershell and .NET you can have the power of WOL without having to resort to third-party applications! Code/Script: param ( $targetMac, $network = [net.ipaddress]::Broadcast, $subnet = [net.ipaddress]::Broadcast ) try { if($network.gettype().equals([string])) { $network = [net.ipaddress]::Parse($network); } if($subnet.gettype().equals([string])) [...]]]></description>
			<content:encoded><![CDATA[<p>Despite what others may say, Wake-on-LAN isn&#8217;t magic and isn&#8217;t that complicated a feat to do anymore. With Powershell and .NET you can have the power of WOL without having to resort to third-party applications!</p>
<h2>Code/Script:</h2>
<pre>param (
    $targetMac,
    $network = [net.ipaddress]::Broadcast,
    $subnet = [net.ipaddress]::Broadcast
)
try {
    if($network.gettype().equals([string])) {
        $network = [net.ipaddress]::Parse($network);
    }
    if($subnet.gettype().equals([string])) {
        $subnet = [net.ipaddress]::Parse($subnet);
    }
    $broadcast = new-object net.ipaddress (([system.net.ipaddress]::parse("255.255.255.255").address -bxor $subnet.address -bor $network.address))

    $mac = [Net.NetworkInformation.PhysicalAddress]::Parse($targetMac.toupper().replace(".",""))

    $u = New-Object net.sockets.udpclient
    $ep = New-Object net.ipendpoint $broadcast, 0
    $ep2 = New-Object net.ipendpoint $broadcast, 7
    $ep3 = New-Object net.ipendpoint $broadcast, 9

    $payload = [byte[]]@(255,255,255, 255,255,255);
    $payload += ($mac.GetAddressBytes()*16)

    for($i = 0; $i -lt 10; $i++) {
        $u.Send($payload, $payload.Length, $ep) | Out-Null
        $u.Send($payload, $payload.Length, $ep2) | Out-Null
        $u.Send($payload, $payload.Length, $ep3) | Out-Null
        sleep 1;
    }
} catch {
    $Error | Write-Error;
}</pre>
<h2>Usage:</h2>
<pre>
wol.ps1 "target-MAC"
wol.ps1 "target-MAC" 192.168.1.255
wol.ps1 "target-MAC" 192.168.1.123 255.255.255.0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2010/05/07/785/wake-on-lan-wol-via-powershell/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Net View for PowerShell</title>
		<link>http://josherickson.org/2010/03/31/775/net-view-for-powershell</link>
		<comments>http://josherickson.org/2010/03/31/775/net-view-for-powershell#comments</comments>
		<pubDate>Wed, 31 Mar 2010 16:02:06 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[netview.ps1]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=775</guid>
		<description><![CDATA[A little PowerShell tool that wraps around &#8220;Net view&#8221; and outputs objects instead of plain text. param ( [string]$Computer, [string]$Domain, [switch]$Cache, [switch]$All, [switch]$ResolveIP, [switch]$GetOS, [System.Management.Automation.PSCredential]$Credentials ) #Take some notes and clean up stuff. if($Computer.length -gt 1 -and !$Computer.startswith("\\")) { $Computer = "\\$computer"; #$computer = "/computer $computer"; } if($Domain.length -gt 1) { $Domain = "/DOMAIN:$Domain"; } [...]]]></description>
			<content:encoded><![CDATA[<p>A little PowerShell tool that wraps around &#8220;Net view&#8221; and outputs objects instead of plain text.</p>
<pre><#
.Synopsis
Parses the "net view" command into PowerShell objects for easy usage.
.description
Switches and parameters are copied stright from "Net view".

Return objects are named after the output table headers in net view.

NETVIEW.PS1 displays a list of resources being shared on a computer. When used without options, it displays a list of computers in the current domain or network.
.parameter Computer
    Is a computer whose shared resources you want to view.
.parameter Domain
    Specifies the domain for which you want to view the available computers. If domainname is omitted, displays all domains in the local area network.
.parameter Cache
    Displays the offline client caching settings for the resources on the specified computer
.parameter All
    Displays all the shares including the $ shares
.parameter ResolveIP
    Resolves the NetBIOS names to their network IP addresses.
.parameter GetOS
    Uses CIM_OperatingSystem WMI class to obtain the operating system.
.parameter Credentials
    Optional credentials to use for GetOS.

#>
param (
    [string]$Computer,
    [string]$Domain,
    [switch]$Cache,
    [switch]$All,
	[switch]$ResolveIP,
    [switch]$GetOS,
    [System.Management.Automation.PSCredential]$Credentials
)

#Take some notes and clean up stuff.
if($Computer.length -gt 1 -and !$Computer.startswith("\\")) {
    $Computer = "\\$computer";
    #$computer = "/computer $computer";
}
if($Domain.length -gt 1) {
    $Domain = "/DOMAIN:$Domain";
}

if($Cache.ispresent) {
    $_Cache = "/CACHE";
}

if($All.ispresent) {
    $_All = "/ALL";
}

try {
    try {
        $nv_raw = (powershell "&#038; { net view $Computer $_Cache $_All $Domain }" 2>&#038;1)
        if(($nv_raw | where {$_.tolower().contains("error")})) { throw $nv_raw; }
    } catch{
        $nv_raw | where {$_}
        exit;
    }

    #If computer isn't defined, we just want to parse the net view output as a list of computers.
    if($Computer.length -eq 0) {
        $nv = $nv_raw | where {$_.startswith("\\")} | foreach { @{"name" = $_.substring(2,$_.indexof(" ")-2).replace(" ",""); "remark" = [regex]::Split($_, "( ){2,}")[2]} }
        foreach($a in $nv) {
            #return object
        	$r = new-object object;

            Add-Member -InputObject $r -MemberType NoteProperty -Name "ServerName" -Value $a.name;
            Add-Member -InputObject $r -MemberType NoteProperty -Name "Remarks" -Value $a.remark;

            if($GetIP.IsPresent) {
                try {
                    Add-Member -InputObject $r -MemberType NoteProperty -Name "AddressList" -Value ([net.dns]::GetHostEntry($r.ServerName).addresslist);
                }
                catch {}
            }

            Add-Member -InputObject $r -MemberType ScriptMethod -Force -Name "ToString" -Value {
                try {
                    return $this.ServerName +"|"+ [string]::Join("|", ($this.Addresslist));
                }
                catch{
                    return $this.ServerName;
                }
            }

            if($GetOS.ispresent) {
                try {
                    #if this computer is the one we're currently working on we can't use the gwmi credentials parameter
                    if($r.ServerName -ne (hostname)) {
                        Add-Member -InputObject $r -MemberType NoteProperty -Name "OS" -Value (gwmi CIM_OperatingSystem -ComputerName $r.ServerName -Credential $Credentials).caption
                    } else {
                        Add-Member -InputObject $r -MemberType NoteProperty -Name "OS" -Value (gwmi CIM_OperatingSystem -ComputerName $r.ServerName).caption
                    }
                } catch {
					$Error | write-error;
                    Add-Member -InputObject $r -MemberType NoteProperty -Name "OS" -Value "N/A"
                }
            }

            #output the object.
            $r;
        }
    } else {
        #Start of lines that we DON'T want.
        $lines = @("Shared resources at", "Share name", "-----------", "The command completed successfully.");

        foreach($l in $nv_raw) {
            if(($lines | where {$l.startswith($_);}) -eq $null -and $l.length -gt 0) {
               $r = New-Object object;
               $t = [regex]::Split($l, "( ){2,}") | where {$_.replace(" ","").length -gt 0};
               Add-Member -InputObject $r -MemberType NoteProperty -Name "Name" -Value $t[0];
               Add-Member -InputObject $r -MemberType NoteProperty -Name "Type" -Value $t[1];
               Add-Member -InputObject $r -MemberType ScriptProperty -Name "Secret" -Value {
                    $this.ShareName.EndsWith("$");
               }
               if($t.length -gt 3) {
                   Add-Member -InputObject $r -MemberType NoteProperty -Name "UsedAs" -Value $t[2];
                   Add-Member -InputObject $r -MemberType NoteProperty -Name "Comment" -Value $t[3];
               } else {
                   Add-Member -InputObject $r -MemberType NoteProperty -Name "Comment" -Value $t[2];
               }
               $r;
            }
        }
    }
} catch {
    $Error | Write-Error
}</pre>
<p><em>Edit: Fixed some variable name errors.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2010/03/31/775/net-view-for-powershell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MS-SQL Powershell database backup</title>
		<link>http://josherickson.org/2009/09/09/580/ms-sql-powershell-database-backup</link>
		<comments>http://josherickson.org/2009/09/09/580/ms-sql-powershell-database-backup#comments</comments>
		<pubDate>Wed, 09 Sep 2009 20:25:18 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[concepts]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=580</guid>
		<description><![CDATA[Recently one of our SQL clusters decided it was a good idea to not backup databases anymore. So today my boss told me to get something to bandaid the situation until we can fix the situation (which will likely be an upgrade/reinstall). To learn more check out the MSDN pages on the Microsoft.SqlServer.Management.Smo namespace. # [...]]]></description>
			<content:encoded><![CDATA[<p>Recently one of our SQL clusters decided it was a good idea to not backup databases anymore. So today my boss told me to get something to bandaid the situation until we can fix the situation (which will likely be an upgrade/reinstall).</p>
<p>To learn more check out the MSDN pages on the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx">Microsoft.SqlServer.Management.Smo</a> namespace.</p>
<pre>
#
#	Temp database backup
#
$d = date;

#filename: db_full_MM-DD-YYYY-HH.bak
$backupfile = "db_full_" + ($d.ToShortDateString().replace("/","-")) + "-" + ($d.hour) + "h.bak";

#should you use drive paths (ie c:\) it will save to the SQL server's drive.
$backuppath = "\\path\to\save\location\doesnt\need\to\be\unc\";

[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo");
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended");
$ser = New-Object "Microsoft.SqlServer.Management.Smo.Server" "server\instance";
$backup = New-Object Microsoft.SqlServer.Management.Smo.Backup
$bdevice = New-Object microsoft.sqlserver.management.smo.backupdeviceitem -ArgumentList ($backuppath + $backupfile), "File"

$backup.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
$backup.BackupSetName = "Daily Full Database";
$backup.Database = "DatabaseName"

$backup.Initialize = $True
$backup.Checksum = $True
$backup.ContinueAfterError = $true
$backup.Devices.Add($bdevice)
$backup.Incremental = $false
$backup.CopyOnly = $true
$backup.LogTruncation ="NoTruncate" #meant for bandaid approach and for less "impact" on database.
$backup.FormatMedia = $false
$backup.SqlBackup($ser); #save it.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/09/09/580/ms-sql-powershell-database-backup/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Link Dump#1: Je.org</title>
		<link>http://josherickson.org/2009/08/24/567/link-dump1-je-org</link>
		<comments>http://josherickson.org/2009/08/24/567/link-dump1-je-org#comments</comments>
		<pubDate>Mon, 24 Aug 2009 21:26:19 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[blah]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[Link Dump #1]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=567</guid>
		<description><![CDATA[In part of finding out if people like what I&#8217;m posting, I from time to time do a google search for the site or myself. Today, I came across some kind of neat links, some of my internet life and some of other people who unfortunatly share my name. http://www.cafepress.com/je_org //Probably the only place on [...]]]></description>
			<content:encoded><![CDATA[<p>In part of finding out if people like what I&#8217;m posting, I from time to time do a google search for the site or myself. Today, I came across some kind of neat links, some of my internet life and some of other people who unfortunatly share my name.</p>
<ul>
<li><a href="http://www.cafepress.com/je_org">http://www.cafepress.com/je_org</a> <span style="color: #339966;">//Probably the only place on the internet where you can buy a shirt about a place that&#8217;s about nothing.</span></li>
<li><a href="http://www.linkedin.com/pub/dir/Joshua/Erickson/?trk=ppro_find_others">http://www.linkedin.com/pub/dir/Joshua/Erickson/?trk=ppro_find_others</a></li>
<li><a href="http://twitter.com/xybreeder">http://twitter.com/xybreeder</a></li>
<li><a href="http://www.plaxo.com/directory/profile/12885112599/316d16e1/Josh/Erickson">http://www.plaxo.com/directory/profile/12885112599/316d16e1/Josh/Erickson</a></li>
<li><a href="http://jenn.com/canadian/jan04.html">http://jenn.com/canadian/jan04.html</a> <span style="color: #339966;">//Not sure why I wanted to become an honorary Canadian&#8230;</span></li>
<li><a href="http://staff.hard-light.net/common/smf2beta/index.php?action=profile;u=516">http://staff.hard-light.net/common/smf2beta/index.php?action=profile;u=516</a> <span style="color: #339966;">//I sometimes wonder if I should start this again.</span></li>
<li><a href="http://www.jericksondesigns.com/">http://www.jericksondesigns.com/</a><span style="color: #339966;">//Probably miffed that I have josherickson.com!</span></li>
<li><a href="http://www.mshssca.org/historical_records.html">http://www.mshssca.org/historical_records.html</a></li>
<li><a href="http://www.bcxc.org/">http://www.bcxc.org/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/08/24/567/link-dump1-je-org/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>There is no duck</title>
		<link>http://josherickson.org/2009/07/09/465/there-is-no-duck</link>
		<comments>http://josherickson.org/2009/07/09/465/there-is-no-duck#comments</comments>
		<pubDate>Thu, 09 Jul 2009 21:28:53 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[blah]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[lex]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=465</guid>
		<description><![CDATA[I&#8217;ll often hear about some crazy law that&#8217;s on the books like it being illegal to cross the Minnesota border with a duck on ones head. One thing though you never see with any of these postings is references to those laws. In the case of the head duck, I looked myself and couldn&#8217;t find [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll often hear about some crazy law that&#8217;s on the books like it being illegal to cross the Minnesota border with a duck on ones head. One thing though you never see with any of these postings is references to those laws.</p>
<p>In the case of the head duck, I looked myself and couldn&#8217;t find anything during my <a href="https://www.revisor.leg.state.mn.us/search/?search=all&#038;stat=1&#038;laws=1&#038;rule=1">search of Minnesota Laws</a>. I didn&#8217;t search the statutes, but a simple <a href="http://www.google.com/search?hl=en&#038;rlz=1C1GGLS_enUS322US322&#038;q=duck+head+border+site:https://www.revisor.leg.state.mn.us&#038;aq=f&#038;oq=&#038;aqi=">google search</a> didn&#8217;t turn up anything either.</p>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/07/09/465/there-is-no-duck/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time filter: C# Project files</title>
		<link>http://josherickson.org/2009/06/18/418/time-filter-c-project-files</link>
		<comments>http://josherickson.org/2009/06/18/418/time-filter-c-project-files#comments</comments>
		<pubDate>Thu, 18 Jun 2009 20:46:53 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[blah]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dump]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=418</guid>
		<description><![CDATA[Here&#8217;s a clightly cleaned up and better version of my time filter project thing, businesshours.zip. Archive contains code, build batch file, and binary. Some changes this round: Takes into account timezones. No longer is missing a day in it&#8217;s calculations. Debugging command line argument to track the inner workings. Should I feel like it: Code cleanup [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a clightly cleaned up and better version of my <a href="http://josherickson.org/2009/06/17/409/time-filtering-for-helpdesks">time filter project</a> thing, <a href="http://josherickson.org/wp-content/uploads/businesshours.zip">businesshours.zip</a>. Archive contains code, build batch file, and binary.</p>
<p>Some changes this round:</p>
<ul>
<li>Takes into account timezones.</li>
<li>No longer is missing a day in it&#8217;s calculations.</li>
<li>Debugging command line argument to track the inner workings.</li>
</ul>
<p>Should I feel like it:</p>
<ul>
<li>Code cleanup</li>
<li>Delete unused variables</li>
<li>Useful comments</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/06/18/418/time-filter-c-project-files/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time filtering: PHP version</title>
		<link>http://josherickson.org/2009/06/17/414/time-filtering-php-version</link>
		<comments>http://josherickson.org/2009/06/17/414/time-filtering-php-version#comments</comments>
		<pubDate>Wed, 17 Jun 2009 21:17:26 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[concepts]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=414</guid>
		<description><![CDATA[As mentioned before, I originally wrote my time filter in PHP but converted it to C# for speed. So here it is for posterity and reference. class nonWorkRanges { public $parse; public $start; public $end; /* this::start and this::end stucture day = 1...31 month = 1...12 (xx = reoccurring) year = YYYY (xxxx = reoccurring) [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://josherickson.org/2009/06/17/409/time-filtering-for-helpdesks">As mentioned before</a>, I originally wrote my time filter in PHP but converted it to C# for speed. So here it is for posterity and reference.</p>
<pre>class nonWorkRanges {
	public $parse;
	public $start;
	public $end;

	/*
		this::start and this::end stucture

		day = 1...31
		month = 1...12 (xx = reoccurring)
		year = YYYY (xxxx = reoccurring)
		weekday = 0...6 (sunday...saturday, if this is set we ignore the day, month, and year values)
		hour = 0...23
		minute = 0...59
		second = 0...59
	*/

	public function businessTime($created, $response) {
		$start = $this-&gt;start;
		$end = $this-&gt;end;

		if(isset($this-&gt;start['weekday']) and isset($this-&gt;end['weekday'])) {
			$ticks = 0;
			$days = date('z', $response) - date('z', $created) + 1;

			$basetime = mktime(0, 0, 0, date('m',$created), date('j',$start['weekday']), date('Y',$created));

			for($dayi=0; $dayi&lt;$days;$dayi++) {

				$day_start = mktime(0, 0, 0, date('m',$basetime), date('j', $basetime)+$dayi, date('Y',$basetime));
				$day_end = mktime(23, 59, 59, date('m',$basetime), date('j', $basetime)+$dayi, date('Y',$basetime));
				$dow = date('w', $day_start);

				if($start['weekday'] &lt; $end['weekday'] &#038;&#038; ($dow &lt; $start['weekday'] || $dow &gt; $end['weekday'])) {
					continue;
				}

				if($start['weekday'] &gt; $end['weekday'] &#038;&#038; ($dow &gt; $start['weekday'] || $dow &lt; $end['weekday'])) {
					//var_dump($start['weekday'] &lt; $end['weekday'], ($dow &gt; $start['weekday'] || $dow &lt; $end['weekday']));
					continue;
				}

				$mask_start = mktime($start['hour'], $start['minute'], $start['second'], date('m',$day_start), ((date('j',$day_start)-date('w',$day_start))+$start['weekday']), date('Y',$day_start));
				$mask_end = mktime($end['hour'], $end['minute'], $end['second'], date('m',$day_start), ((date('j',$day_start)-date('w',$day_start))+$end['weekday']), date('Y',$day_start));

				for($i=0; $i&lt;86400; $i++) {
					$loc = $day_start + $i;
					$tf = array(
						$loc &lt; $created,
						$loc &gt; $response,
						$loc &lt; $mask_start,
					 	$loc &gt; $mask_end
					);
					if((!$tf[0] &#038;&#038; !$tf[1]) &#038;&#038; (!$tf[2] &#038;&#038; !$tf[3])) {
						$ticks++;
					}
				}
			}
			return $ticks;
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/06/17/414/time-filtering-php-version/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time filtering for helpdesks</title>
		<link>http://josherickson.org/2009/06/17/409/time-filtering-for-helpdesks</link>
		<comments>http://josherickson.org/2009/06/17/409/time-filtering-for-helpdesks#comments</comments>
		<pubDate>Wed, 17 Jun 2009 15:46:31 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[concepts]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dump]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=409</guid>
		<description><![CDATA[One of the goals this year is to have an average response time of 15 minutes for all helpdesk tickets, but we have one problem, no way to track or know if we&#8217;re getting closer. During my initial research, the only thing I could find was code that couldn&#8217;t be customized through configuration files so [...]]]></description>
			<content:encoded><![CDATA[<p>One of the goals this year is to have an average response time of 15 minutes for all helpdesk tickets, but we have one problem, no way to track or know if we&#8217;re getting closer.</p>
<p>During my initial research, the only thing I could find was code that couldn&#8217;t be customized through configuration files so it would be easier for management to configure later. Since the tool we wanted to get the reports from was Eventum, I originally wrote this in PHP, but it proved way to slow and so I converted it into a C# app to handle the calculations.</p>
<p>Besides the code below, you&#8217;ll need <a href='http://josherickson.org/wp-content/uploads/masks.xml'>masks.xml</a>, which holds the info about business hours.</p>
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace eventum_responsetime
{
    class Program
    {
		//businesshours.exe -created "any date format DateTime can parse" -response "any date format DateTime can parse"
        static void Main(string[] args)
        {
            System.DateTime base_unixtime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
            long int_base_unixtime = base_unixtime.Ticks / 10000000;

            if (args == null || args.Length == 0)
            {
                args = new string[] { "nothing" };
            }

            System.Collections.Hashtable hargs = new System.Collections.Hashtable();

            hargs.Add("nothing", Array.Find(args, (delegate(string s) { if (s.ToLower() == "nothing") { return true; } return false; })));

            hargs.Add("created", args[Array.FindIndex(args, (delegate(string s) { if (s.ToLower() == "-created") { return true; } return false; })) + 1]);
            hargs.Add("response", args[Array.FindIndex(args, (delegate(string s) { if (s.ToLower() == "-response") { return true; } return false; })) + 1]);

			//Load the masked times xml.
            XmlDocument xmld = new XmlDocument();
            xmld.Load("./masks.xml");

            XmlNodeList masks = xmld.GetElementsByTagName("mask");

            nonWorkRanges[] a = new nonWorkRanges[masks.Count];

            long ticks = 0;
            for(int i=0;i&lt;a.Length;i++) {
                XmlNode n = masks[i];

				//Load up the masks
                a[i] = new nonWorkRanges();
                a[i].start.weekday = (n["start"].Attributes["weekday"] == null) ? 0 : int.Parse(n["start"].Attributes["weekday"].Value);
                a[i].start.hour = (n["start"].Attributes["hour"]==null)? 0 : int.Parse(n["start"].Attributes["hour"].Value);
                a[i].start.minute = (n["start"].Attributes["minute"]== null) ? 0 : int.Parse(n["start"].Attributes["minute"].Value);
                a[i].start.second = (n["start"].Attributes["second"] == null) ? 0 : int.Parse(n["start"].Attributes["second"].Value);

                a[i].end.weekday = (n["end"].Attributes["weekday"] == null) ? 0 : int.Parse(n["end"].Attributes["weekday"].Value);
                a[i].end.hour = (n["end"].Attributes["hour"] == null) ? 0 : int.Parse(n["end"].Attributes["hour"].Value);
                a[i].end.minute = (n["end"].Attributes["minute"] == null) ? 0 : int.Parse(n["end"].Attributes["minute"].Value);
                a[i].end.second = (n["end"].Attributes["second"] == null) ? 0 : int.Parse(n["end"].Attributes["second"].Value);

                ticks += a[i].ticks(DateTime.Parse(hargs["created"].ToString()), DateTime.Parse(hargs["response"].ToString()));
            }

			//Output how much business time elapsed.
            Console.WriteLine(ticks.ToString());
        }
    }

    abstract class mask {
        public int weekday;
        public int hour;
        public int minute;
        public int second;

        public DateTime time;
    }

    class startMask : mask
    {

    }

    class endMask : mask
    {

    }

    class nonWorkRanges
    {
        public startMask start;
        public endMask end;

        public nonWorkRanges()
        {
            this.start = new startMask();
            this.end = new endMask();
        }

        public long ticks(DateTime created, DateTime response)
        {
            if (start.weekday != null &#038;&#038; end.weekday != null)
            {
                long ticks = 0;

                int days = (response - created).Days + 1;

                DateTime basetime = new DateTime(created.Year, created.Month, created.Day, 0, 0, 0);

                for (int dayi = 0; dayi &lt; days; dayi++)
                {
                    DateTime day_start = new DateTime(basetime.Year, basetime.Month, basetime.Day, 0, 0, 0);
                    day_start.AddDays(dayi);
                    DateTime day_end = new DateTime(basetime.Year, basetime.Month, basetime.Day, 23, 59, 59);
                    day_end.AddDays(dayi);

                    int dow = (int)(day_start.DayOfWeek);

                    if (start.weekday &lt; end.weekday &#038;&#038; (dow &lt; start.weekday || dow &gt; end.weekday))
                    {
                        continue;
                    }
                    if (start.weekday &gt; end.weekday &#038;&#038; (dow &gt; start.weekday || dow &lt; end.weekday))
                    {
                        continue;
                    }

                    DateTime mask_start = new DateTime(day_start.Year, day_start.Month, day_start.Day, start.hour, start.minute, start.second);
                    mask_start = mask_start.AddDays(-dow).AddDays(start.weekday);

                    DateTime mask_end = new DateTime(day_start.Year, day_start.Month, day_start.Day, end.hour, end.minute, end.second);
                    mask_end = mask_end.AddDays(-dow).AddDays(end.weekday);

                    for (int i = 0; i &lt; 86400; i++)
                    {
                        DateTime loc = day_start.AddSeconds(i);

						//Simply to make reading the if block easier.
                        bool[] tf = new bool[] {
                            loc &lt; created,
                            loc &gt; response,
                            loc &lt; mask_start,
                            loc &gt; mask_end
                        };

                        if((!tf[0] &#038;&#038; !tf[1]) &#038;&#038; (!tf[2] &#038;&#038; !tf[3]))
                        {
                            ticks++;
                        }
                    }
                }
                return ticks;
            }
            return 0;
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/06/17/409/time-filtering-for-helpdesks/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Route Kill v2</title>
		<link>http://josherickson.org/2009/06/05/389/route-kill-v2</link>
		<comments>http://josherickson.org/2009/06/05/389/route-kill-v2#comments</comments>
		<pubDate>Fri, 05 Jun 2009 16:56:51 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[concepts]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=389</guid>
		<description><![CDATA[Last time around, Route Kill was pretty simple, just misdirect a route. This time, I added a little more code flexibility, some minor network monitoring and a maliciousness not seen before. This time, it kills the route (deletes the route from the table), packets aren&#8217;t even misdirected, they go nowhere! To get things ready for [...]]]></description>
			<content:encoded><![CDATA[<p>Last time around, <a href="http://www.dreamincode.net/code/snippet2832.htm">Route Kill</a> was pretty simple, just misdirect a route. This time, I added a little more code flexibility, some minor network monitoring and a maliciousness not seen before. This time, it kills the route (deletes the route from the table), packets aren&#8217;t even misdirected, they go nowhere!</p>
<p>To get things ready for yourself, just edit the (routeWatcher)routeList in Main() to suit your network and requirements. Then run the following in the command line below and then just sit back and watch the mayhem.</p>
<pre>cd C:\Windows\Microsoft.NET\Framework\v3.5
.\csc.exe /t:winexe /out:c:\routekill.exe C:\program.cs</pre>
<pre>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;

namespace routeKill
{
    class Program
    {
        static void Main(string[] args)
        {

            //We need two, one for the local tubes, and one for the intertubes.
            routeWatcher[] routeList = new routeWatcher[2];
            routeList[0] = new routeWatcher(new routeId("0.0.0.0", "24.217.29.127")); //24.217.29.127 = charter.com
            routeList[0].onRouteActive += Program.killRoute;

            routeList[1] = new routeWatcher(new routeId("192.168.1.0", "192.168.1.1"));
            routeList[1].onRouteActive += Program.killRoute;

            Thread[] rthread = new Thread[routeList.Length];

            for (int i=0;i&lt;routeList.Length; i++)
            {
                rthread[i] = new Thread(routeList[i].Start);
                rthread[i].Start();
            }

            //A kill order for when you just don't want to get in there yourself.
            //routekill.exe -timeout {Milliseconds}
            System.Collections.Hashtable hargs = new System.Collections.Hashtable();
            hargs.Add("timeout", Array.Find(args, (delegate(string s) { if (s.ToLower() == "-timeout") { return true; } return false; })));
            if (hargs["timeout"] != null)
            {
                Thread.Sleep(int.Parse(hargs["timeout"].ToString()));
                //Process.GetCurrentProcess().Kill();
				foreach(Thread t in rthread) {
					t.Abort();
				}
            }

            return;
        }

        static void killRoute(routeId network)
        {
            Process a = new Process();
            a.StartInfo.CreateNoWindow = true;
            a.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            a.StartInfo.FileName = "route";
            a.StartInfo.Arguments = string.Format("delete {0}", network.network);
            a.Start();
            a.Close();
        }
    }

    class routeId
    {
        private string _network;

        public string network
        {
            get { return this._network; }
        }

        private string _heartbeatIP;
        public string heartbeatIP { get { return this._heartbeatIP; } }

        public routeId(string network)
        {
            this._network = network;
        }

        public routeId(string network, string heartbeat)
        {
            this._network = network;
            this._heartbeatIP = heartbeat;
        }
    }

    class routeWatcher
    {
        public delegate void RouteActive(routeId network);

        public event RouteActive onRouteActive;

        private routeId network;
        public routeWatcher(routeId network)
        {
            this.network = network;
        }

        public void Start()
        {

            System.Net.NetworkInformation.Ping a;
            while (true)
            {
                a = new System.Net.NetworkInformation.Ping();
                System.Net.NetworkInformation.PingReply ar = a.Send(this.network.heartbeatIP);
                if (ar.Status.Equals(System.Net.NetworkInformation.IPStatus.Success))
                {
                    //RouteActive(this.network);
                    if(this.onRouteActive != null) this.onRouteActive(this.network);
                }
                Thread.Sleep(1000);

            }
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/06/05/389/route-kill-v2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>1989 Tiananmen Square Protests</title>
		<link>http://josherickson.org/2009/06/05/387/1989-tiananmen-square-protests</link>
		<comments>http://josherickson.org/2009/06/05/387/1989-tiananmen-square-protests#comments</comments>
		<pubDate>Fri, 05 Jun 2009 06:01:53 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[dump]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://josherickson.org/?p=387</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/9-nXT8lSnPQ&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/9-nXT8lSnPQ&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://josherickson.org/2009/06/05/387/1989-tiananmen-square-protests/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
