PowerShell Cookbook

Search

Categories

 

On this page

Archive

Blogroll

Disclaimer
I work for Microsoft.

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 214
This Year: 14
This Month: 1
This Week: 0
Comments: 522

Sign In

 Tuesday, August 29, 2006
Wednesday, August 30, 2006 5:07:43 AM (Pacific Daylight Time, UTC-07:00) ( )

Probably the most useful network tool on any operating system is Telnet.  Not for connecting to Telnet servers, of course, as the Telnet protocol is about as insecure as they come.  Instead, it’s useful for debugging connection problems with arbitrary ports and arbitrary protocols.

Debugging an HTTP problem?  You can Telnet into port 80 to help you resolve it.
Debugging a mail retrieval issue?  You can Telnet into port 110 to help you resolve it.
Debugging a mail sending issue?  You can Telnet into port 25 to help you resolve it.
<etc>

Unfortunately, this workhorse was removed from Vista’s default installation.  Here’s a simple PowerShell replacement script.  It’s great for debugging, but useless (of course) for terminal emulation:

 

## Connect-Computer.ps1
## Interact with a service on a remote TCP port
param(
    [string] $remoteHost = "localhost",
    [int] $port = 80
     )

## Open the socket, and connect to the computer on the specified port
write-host "Connecting to $remoteHost on port $port"
$socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port)
if($socket -eq $null) { return; }

write-host "Connected.  Press ^D followed by [ENTER] to exit.`n"

$stream = $socket.GetStream()
$writer = new-object System.IO.StreamWriter($stream)

$buffer = new-object System.Byte[] 1024
$encoding = new-object System.Text.AsciiEncoding

while($true)
{
   ## Allow data to buffer for a bit
   start-sleep -m 500

   ## Read all the data available from the stream, writing it to the
   ## screen when done.
   while($stream.DataAvailable) 
   { 
      $read = $stream.Read($buffer, 01024)   
      write-host -n ($encoding.GetString($buffer, 0, $read)) 
   }

   ## Read the user's command, quitting if they hit ^D
   $command = read-host
   if($command -eq ([char4)) { break; }
 
   ## Write their command to the remote host     
   $writer.WriteLine($command)
   $writer.Flush()
}

## Close the streams
$writer.Close()
$stream.Close()

Saturday, September 02, 2006 5:20:22 PM (Pacific Daylight Time, UTC-07:00)
Vista has both a Telnet client and a Telnet server built-in. They're just off by default.

You can find them in the "Turn Windows Features On or Off" dialog inside the Programs control panel.
Saturday, September 09, 2006 11:46:41 PM (Pacific Daylight Time, UTC-07:00)
Hi,

I wrote for myself a Web service to telnet very simply any server. As t proved to be very useful, I propose it to everyone on the web: http://browseas.com/telnet.php
Sunday, September 10, 2006 12:08:52 AM (Pacific Daylight Time, UTC-07:00)
Nice job! It hung when I tried to use any interactive protocols, though :)
Thursday, April 24, 2008 1:46:43 PM (Pacific Daylight Time, UTC-07:00)
Well, AbsoluteTelnet is indeed a good one, but it's not commandline-based and it's not free.
You might wanna consider PuTTY instead, or just enable it again in Vista ...
L. Dopa
Name
E-mail
Home page

Comment (Some html is allowed: b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):