I'm making my own network tool and I am implementing an ssh option to ssh to a server but when I test it with an ssh server I got online, I can enter and ssh into it but when I run commands ex: ls, mkdir, etc. I just get an empty bracket as output. The output looks like this: "[]". Literally that's the output I get instead of actually executing the commands I want. How can I fix this???
pyNet code:
import socket
import time
import urllib
import pyfiglet
import paramiko
import ipaddress
import subprocess
import sys
import os
import scapy.all as scapy
from datetime import datetime
# banner
print("*" * 100)
ascii_banner = pyfiglet.figlet_format("ALL IN ONE")
print(ascii_banner)
print("*" * 100)
# ping host
def ping(host):
res = os.system("ping -c 10 " + host)
if res == 0:
print("")
print("Connection is alive....")
else:
print("Connection is down....")
# scan ports
def port_scanner():
print("")
host = input("Enter website to scan: ")
ip = socket.gethostbyname(host)
print("*" * 60)
print("Please wait, scanning host", ip)
print("*" * 60)
t = datetime.now()
try:
for port in range(1, 65535):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((ip, port))
if result == 0:
print("Port {}: Open".format(port))
sock.close()
except KeyboardInterrupt:
print("You pressed Ctrl+C")
sys.exit()
except socket.gaierror:
print("Hostname could not be resolved.... Exiting")
sys.exit()
except socket.error:
print("Couldn't connect to server")
sys.exit()
t2 = datetime.now()
total = t2 - t
print("Scan Completed in: ", total)
# ssh session
def ssh_option():
ip = input("Enter url: ")
t_ipaddr = socket.gethostbyname(ip)
print("Making connection to:", t_ipaddr)
user = input("Enter your username: ")
passwd = input("Enter you password: ")
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(t_ipaddr, username=user, password=passwd, look_for_keys=False)
command = input("Enter command: ")
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(command)
output = ssh_stdout.readlines()
print(ssh_stdin)
ssh.close()
# menu
run = True
while run:
print("Enter an option (1 - 3)")
print("")
print("1. Ping")
print("2. Scan Ports")
print("3. SSH")
choice = int(input("cmd: "))
if choice == 1:
url = input("enter website url: ")
print(ping(url))
if choice == 2:
port_scanner()
if choice == 3:
ssh_option()