<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: More Powershell &#8211; Test-TcpPort</title>
	<atom:link href="http://halr9000.com/article/418/feed" rel="self" type="application/rss+xml" />
	<link>http://halr9000.com/article/418</link>
	<description>(powershell &#38; other stuff)</description>
	<lastBuildDate>Thu, 17 May 2012 06:21:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Meik</title>
		<link>http://halr9000.com/article/418/comment-page-1#comment-7864</link>
		<dc:creator>Meik</dc:creator>
		<pubDate>Fri, 08 Apr 2011 13:52:09 +0000</pubDate>
		<guid isPermaLink="false">http://halr9000.com/article/418#comment-7864</guid>
		<description>Hi,

but if you don&#039;t want to install 3rd party tools, this script is very usefull.
For error-trapping you could use try {...} catch {...} as follows:

Code:
filter Test-TcpPort {

  Param([int]$port = 80,
	[string]$horst)
  $socket = new-object Net.Sockets.TcpClient
try {
$socket.Connect($horst, $port)
 if ($socket.Connected) {
  $status = &quot;Open&quot;
  $socket.Close()
 }
  else {
    $status = &quot;Closed / Filtered&quot;
  }
 } catch { $status = &quot;Closed / Filtered&quot; }
 $socket = $null
 write-output &quot;$horst`t$port`t$status&quot;
}</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>but if you don&#8217;t want to install 3rd party tools, this script is very usefull.<br />
For error-trapping you could use try {&#8230;} catch {&#8230;} as follows:</p>
<p>Code:<br />
filter Test-TcpPort {</p>
<p>  Param([int]$port = 80,<br />
	[string]$horst)<br />
  $socket = new-object Net.Sockets.TcpClient<br />
try {<br />
$socket.Connect($horst, $port)<br />
 if ($socket.Connected) {<br />
  $status = &#8220;Open&#8221;<br />
  $socket.Close()<br />
 }<br />
  else {<br />
    $status = &#8220;Closed / Filtered&#8221;<br />
  }<br />
 } catch { $status = &#8220;Closed / Filtered&#8221; }<br />
 $socket = $null<br />
 write-output &#8220;$horst`t$port`t$status&#8221;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: halr9000</title>
		<link>http://halr9000.com/article/418/comment-page-1#comment-7385</link>
		<dc:creator>halr9000</dc:creator>
		<pubDate>Thu, 15 Oct 2009 01:41:58 +0000</pubDate>
		<guid isPermaLink="false">http://halr9000.com/article/418#comment-7385</guid>
		<description>I haven&#039;t touched this .NET object in a while actually. As much as I was teasing NMAP, it is still such a cool tool that you may want to use it in combination with a script to parse the results. There&#039;s at least one example out there of using PowerShell to do this: http://blogs.sans.org/windows-security/2009/06/11/powershell-script-to-parse-nmap-xml-output/</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t touched this .NET object in a while actually. As much as I was teasing NMAP, it is still such a cool tool that you may want to use it in combination with a script to parse the results. There&#8217;s at least one example out there of using PowerShell to do this: <a href="http://blogs.sans.org/windows-security/2009/06/11/powershell-script-to-parse-nmap-xml-output/" rel="nofollow">http://blogs.sans.org/windows-security/2009/06/11/powershell-script-to-parse-nmap-xml-output/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeremyinNC</title>
		<link>http://halr9000.com/article/418/comment-page-1#comment-7358</link>
		<dc:creator>JeremyinNC</dc:creator>
		<pubDate>Fri, 09 Oct 2009 00:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://halr9000.com/article/418#comment-7358</guid>
		<description>How long was your timeout lasting? I am interested in wrapping this into a script that would scan all my DMZ hosts once a day and dump to a file and then email me if there where any differences.</description>
		<content:encoded><![CDATA[<p>How long was your timeout lasting? I am interested in wrapping this into a script that would scan all my DMZ hosts once a day and dump to a file and then email me if there where any differences.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnaud Petitjean</title>
		<link>http://halr9000.com/article/418/comment-page-1#comment-5821</link>
		<dc:creator>Arnaud Petitjean</dc:creator>
		<pubDate>Tue, 11 Sep 2007 15:27:05 +0000</pubDate>
		<guid isPermaLink="false">http://halr9000.com/article/418#comment-5821</guid>
		<description>Hi Hal,

You are right, testing $_ is a non sense.

Arnaud</description>
		<content:encoded><![CDATA[<p>Hi Hal,</p>
<p>You are right, testing $_ is a non sense.</p>
<p>Arnaud</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: halr9000</title>
		<link>http://halr9000.com/article/418/comment-page-1#comment-5362</link>
		<dc:creator>halr9000</dc:creator>
		<pubDate>Thu, 30 Aug 2007 16:21:36 +0000</pubDate>
		<guid isPermaLink="false">http://halr9000.com/article/418#comment-5362</guid>
		<description>Why did you do { $_ -and $socket.connected } ?  $_ is pretty much assumed this deep into the function, if I were gonna test for $_ I would do it one level up, otherwise the lack of a pipeline sets the status to closed.  Or am I missing something?</description>
		<content:encoded><![CDATA[<p>Why did you do { $_ -and $socket.connected } ?  $_ is pretty much assumed this deep into the function, if I were gonna test for $_ I would do it one level up, otherwise the lack of a pipeline sets the status to closed.  Or am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnaud Petitjean</title>
		<link>http://halr9000.com/article/418/comment-page-1#comment-5357</link>
		<dc:creator>Arnaud Petitjean</dc:creator>
		<pubDate>Thu, 30 Aug 2007 12:30:15 +0000</pubDate>
		<guid isPermaLink="false">http://halr9000.com/article/418#comment-5357</guid>
		<description>Very nice script Hal !

For error testing, you can use the automatic variable $_. But if you do so, you must disable error display by using $ErrorActionPreference = &quot;SilentlyContinue&quot;.

Here&#039;s your modified script :

filter Test-TcpPort {
   ### filter:       Test-TcpPort
   ### description:  Tests to see if a port is open or closed.
   ### version: 0.1
   ### input:
   ###   paramaters (1) (optional, default = 80): [int] port
   ###   object pipeline: [string] IP addresses and hostnames
   ### output:
   ###   [string] â€œ$_ ## statusâ€ where # is port number
   ### TODO: create custom object for output instead of strings
   ###       also need to trap the connect errors
   Param([int]$port = 80)
   $ErrorActionPreference = &quot;SilentlyContinue&quot;

   $socket = new-object Net.Sockets.TcpClient  
   $socket.Connect($_, $port)

   if ($_ -and $socket.Connected) {
       $status = â€œOpenâ€  
       $socket.Close()  
   }  
   else {  
       $status = â€œClosed / Filteredâ€  
   }  
   $socket = $null  
   write-output â€œ$_`t$port`t$statusâ€  
}

Can I put you script in my French Powershell script repository ?

Best regards from France,

Arnaud</description>
		<content:encoded><![CDATA[<p>Very nice script Hal !</p>
<p>For error testing, you can use the automatic variable $_. But if you do so, you must disable error display by using $ErrorActionPreference = &#8220;SilentlyContinue&#8221;.</p>
<p>Here&#8217;s your modified script :</p>
<p>filter Test-TcpPort {<br />
   ### filter:       Test-TcpPort<br />
   ### description:  Tests to see if a port is open or closed.<br />
   ### version: 0.1<br />
   ### input:<br />
   ###   paramaters (1) (optional, default = 80): [int] port<br />
   ###   object pipeline: [string] IP addresses and hostnames<br />
   ### output:<br />
   ###   [string] â€œ$_ ## statusâ€ where # is port number<br />
   ### TODO: create custom object for output instead of strings<br />
   ###       also need to trap the connect errors<br />
   Param([int]$port = 80)<br />
   $ErrorActionPreference = &#8220;SilentlyContinue&#8221;</p>
<p>   $socket = new-object Net.Sockets.TcpClient<br />
   $socket.Connect($_, $port)</p>
<p>   if ($_ -and $socket.Connected) {<br />
       $status = â€œOpenâ€<br />
       $socket.Close()<br />
   }<br />
   else {<br />
       $status = â€œClosed / Filteredâ€<br />
   }<br />
   $socket = $null<br />
   write-output â€œ$_`t$port`t$statusâ€<br />
}</p>
<p>Can I put you script in my French Powershell script repository ?</p>
<p>Best regards from France,</p>
<p>Arnaud</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shay Levi</title>
		<link>http://halr9000.com/article/418/comment-page-1#comment-4608</link>
		<dc:creator>Shay Levi</dc:creator>
		<pubDate>Fri, 24 Aug 2007 13:01:18 +0000</pubDate>
		<guid isPermaLink="false">http://halr9000.com/article/418#comment-4608</guid>
		<description>Cool stuff, Cheers!

Shay
http://scriptolog.blogspot.com</description>
		<content:encoded><![CDATA[<p>Cool stuff, Cheers!</p>
<p>Shay<br />
<a href="http://scriptolog.blogspot.com" rel="nofollow">http://scriptolog.blogspot.com</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

