I have written a code that connects to the virtual machine (using SSH with Paramiko) and executes several commands. But I do not get the result from the ifconfig
command (the rest of the commands still get normal)
info:
- Python version: 3.7
- Paramiko version: 2.4.2
- OS: Linux 4.18
My code:
#!/usr/bin/env python3
import paramiko
import getpass
def ssh_connect(host, port):
USERNAME = input("username: ")
PASSWORD = getpass.getpass("password: ")
CMDs = ['pwd', 'ifconfig', 'lsblk']
try:
ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.connect(host, port=port, username=USERNAME, password=PASSWORD)
for CMD in CMDs:
print(f"{USERNAME}@{host}$ {CMD}")
_, stdout, stderr = ssh_client.exec_command(CMD.strip())
data_array_return = stdout.read().decode()
for line in data_array_return.split("\n"):
print(str(line))
ssh_client.close()
except Exception as e:
print(e)
def main():
HOST = input("hostname: ")
PORT = int(input("port: "))
ssh_connect(HOST, PORT)
if __name__ == "__main__":
main()
my output
ctnguyenvn[paraSSH]$ ./paramiko_ssh_simple.py
hostname: 192.168.145.10
port: 22
username: linux-victim
password:
linux-victim@192.168.145.10$ pwd
/home/linux-victim
linux-victim@192.168.145.10$ ifconfig
linux-victim@192.168.145.10$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 300M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 27.7G 0 part /
sr0 11:0 1 1024M 0 rom
I don't think my code is wrong. How do I get results from the ifconfig
command?
stderr
for ifconfig
shows:
bash: ifconfig: command not found