panni04

New commands to mimic old utility

Blog Post created by panni04 Employee on Sep 7, 2017

Every now and then I have to test and debug some networking connections.  Not too long ago, we used to have OS packed with utility called 'telnet'.  A good use for telnet was to quickly check access to port on a remote host.  

 

With telnet barely used for anything these days, the telnet program is not available in new operating systems by default.  Sure, there are lots of alternative programs available which can do all kind of fancy stuff.  But, if you are in hurry and don't want to install anything then here is something you can do.

 

Windows OS:  A simple Powershell cmdlet can emulate telnet.  Save this code as "telnet.ps1" and store it in your favourite folder/directory.  

[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$ip,

[Parameter(Mandatory=$True,Position=2)]
[int]$port
)

$connection = New-Object System.Net.Sockets.TcpClient($ip, $port)
if ($connection.Connected) {
Return "Connection Success"
}
else {
Return "Connection Failed"
}

 

Run it in your Powershell like this:

PS C:\tmp> .\telnet.ps1 linux-box 22
Connection Success

 

In Linux, we can use builtin nc or ncat.  Most distros have it these days.

nc -v -i 5 10.10.100.151 22

Ncat: Version 6.40 ( http://nmap.org/ncat )

Ncat: Connected to 10.10.100.151:22.

Ncat: Idle timeout expired (5000 ms).

-v  verbose.

-i  timeout settings. For 5, it will disconnect after 5 seconds or 5000 milliseconds. 

 

Pretty nifty!

Outcomes