Skip to content

Instantly share code, notes, and snippets.

@siasur
Created January 9, 2024 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siasur/91da58038eaae52684ce78d2d5d67deb to your computer and use it in GitHub Desktop.
Save siasur/91da58038eaae52684ce78d2d5d67deb to your computer and use it in GitHub Desktop.
GrayHack, better ssh command tool
//Usages: ssh (user@)ip(:port) -p pass
// * ssh -p pass (user@)ip(:port)
// * ssh -h|-H|-?
//Notice: Do NOT replace your default ssh tool with this script if you make use of Map.exe
// Copyright notice: I've written it, you use it however you like, giving credits would be nice, but I don't require it.
// If you do improve it, I would love to know about it. But that too is not required.
usageHint = "<b>Usage: "+program_path.split("/")[-1]+" <i>(user@)</i>[ip]<i>(:port) (-p pass)</i></b>"
if params.len != 1 and params.len != 3 then exit("<color=#f00>"+usageHint+"</color>")
connection = null
username = active_user
password = null
host = null
port = 22
if params.len == 3 then
if params[0] == "-p" then
password = params[1]
connection = params[2]
else if params[1] == "-p" then
password = params[2]
connection = params[0]
else
exit("<color=#f00>"+usageHint+"</color>")
end if
else
if params[0] == "-h" or params[0] == "-?" or params[0] == "-H" then exit(usageHint)
connection = params[0]
end if
hostStartIndex = 0
hostEndIndex = connection.len
indexUsername = connection.indexOf("@")
if indexUsername then
username = connection[0:indexUsername]
hostStartIndex = indexUsername+1
end if
indexPort = connection.indexOf(":")
if connection.indexOf(":") then
port = connection[indexPort+1:connection.len].to_int
hostEndIndex=indexPort
end if
host = connection[hostStartIndex:hostEndIndex]
if typeof(port) != "number" then exit("<color=#f00>Invalid port: " + port+"</color>")
if typeof(host) != "string" or host.len < 1 then exit("<color=#f00>Invalid host: "+ host+"</color>")
if (typeof(password) != "string") then password = user_input("Enter password: ", true)
print("Connecting...")
shell = get_shell.connect_service(host, port, username, password, "ssh")
if typeof(shell) == "string" then exit(shell)
if shell then
shell.start_terminal
else
print("<color=#f00>connection failed</color>")
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment