Skip to content
This repository was archived by the owner on Oct 12, 2024. It is now read-only.

Commit 73121fa

Browse files
author
RainbowRain
committed
Added SSH Command
1 parent 66f8240 commit 73121fa

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ aioping~=0.3.1
44
aiohttp~=3.8.1
55
asyncoro~=4.5.6
66
yarl~=1.7.2
7-
aiocfscrape~=1.0.0
7+
aiocfscrape~=1.0.0
8+
asyncssh~=2.10.0

tools/impl/Pinger.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from asyncio import sleep, open_connection, TimeoutError, wait_for, create_task
22
from contextlib import suppress
33
from itertools import cycle
4-
from time import time
54

65
from aioconsole import aprint
76
from aiohttp import ClientSession

tools/impl/SSH.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from contextlib import suppress
2+
from getpass import getpass
3+
from aioconsole import aprint
4+
from asyncssh import SSHClientConnection, connect
5+
from tools import Tool
6+
7+
8+
class SSH(Tool):
9+
using = False
10+
11+
@staticmethod
12+
async def run(*args):
13+
assert len(args) == 2, "bad args"
14+
ip, username = str(args[0]).split(":"), args[1] # SSH 185.855.855.690:22 root
15+
password = getpass("Enter Password: ")
16+
await aprint(f"Connecting To {ip[0]}")
17+
try:
18+
with suppress(KeyboardInterrupt):
19+
SSH.using = True
20+
try:
21+
Connection: SSHClientConnection
22+
23+
async with connect(ip[0], port=int(ip[1]), username=username, password=password,
24+
known_hosts=None, connect_timeout=5) as Connection:
25+
while True:
26+
inputcmd = input(f"{username}@{ip[0]}> ")
27+
output = await Connection.run(inputcmd)
28+
await aprint(output.stdout)
29+
except Exception as e:
30+
await aprint(str(e))
31+
finally:
32+
SSH.using = False

tools/impl/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from tools.impl.Pinger import Pinger
22
from tools.impl.cfxFinder import Cfxfinder
3+
from tools.impl.SSH import SSH
34

45
__all__ = ["handle"]
56

@@ -11,4 +12,7 @@ async def handle(cmd, *args):
1112
elif {cmd} & {"CFX"}:
1213
await Cfxfinder.run(*args)
1314
return True
15+
elif {cmd} & {"SSH"}:
16+
await SSH.run(*args)
17+
return True
1418
return False

0 commit comments

Comments
 (0)