Created
September 25, 2018 01:49
-
-
Save Reelix/4d25cbfae2fc2c1aad2132c69ff937de to your computer and use it in GitHub Desktop.
A simple C# app to get the version of a remote IPs SSH client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Sockets; | |
using System.Text; | |
namespace SSHv | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
string IP = ""; | |
int port = 22; | |
if (args.Length == 0) | |
{ | |
Console.WriteLine("Reelix's SSH Version Detector"); | |
Console.WriteLine("sshv IP [port]"); | |
Environment.Exit(0); | |
} | |
else if (args.Length > 0) | |
{ | |
IP = args[0]; | |
if (args.Length == 2) | |
{ | |
port = int.Parse(args[1]); | |
} | |
} | |
TcpClient tcpClient = new TcpClient(); | |
try | |
{ | |
tcpClient.Connect(IP, port); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Cannot connect: " + ex.Message); | |
tcpClient.Close(); | |
Environment.Exit(0); | |
} | |
if (tcpClient.Connected) | |
{ | |
if (tcpClient.ReceiveBufferSize > 0) | |
{ | |
byte[] dataBytes = new byte[tcpClient.ReceiveBufferSize]; | |
tcpClient.ReceiveTimeout = 5000; | |
try | |
{ | |
tcpClient.GetStream().Read(dataBytes, 0, tcpClient.ReceiveBufferSize); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Connected, but no response"); | |
Environment.Exit(0); | |
} | |
string theData = Encoding.ASCII.GetString(dataBytes); | |
theData = theData.Replace("\0", "").Replace(Environment.NewLine, ""); | |
if (theData.Length == 0) | |
{ | |
Console.WriteLine("Connected, but no response"); | |
} | |
else | |
{ | |
Console.WriteLine(theData); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("No response :<"); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("Cannot connect :<"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment