Python Forum
cant use ping, sudo or other commands in remote shell script.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cant use ping, sudo or other commands in remote shell script.
#1
Ive posted about this script in the past and again I have run aground... whenever I try to enter commands In such as sudo, Clear, ping and so on I do not receive any feedback from the server end please help. Wall

client:
#!/usr/bin/env python3
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if True:
	try:
		Host = input('>Remote Host:')
		port = 4444
		s.connect((Host, port))
	except TimeoutError:
		print('Connection Timed out.')
		s.close()
		exit()
	except ConnectionRefusedError:
		print('connection refused.')
		s.close()
		exit()
	except socket.gaierror:
		print('connection refused.')
		s.close()
		exit()
while True:
    cmd = input('>(R)Host:$')
    cmd2 = (cmd).encode('utf-8')
    try:
    	s.sendall(cmd2)
    	data = s.recv(4096)
    	data2 = data.decode('utf-8')
    	print(data2)
    except ConnectionResetError:
    		print('connection was reset.')
    except BrokenPipeError:
    	print('The connection has been closed by the Host.')
server:
#!/usr/bin/env python3

import socket
import platform
import subprocess
s  = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Host = platform.node()
port = 4444
if  True:
	try:
		s.bind((Host, port))
		s.listen(1)
	except OSError:
		print('The script is already running.')
		s.close()
		exit()
conn, addr = s.accept()
while True:
    data = conn.recv(4096)
    data2 = data.decode('utf-8')
    print(data2)
    z = subprocess.run(data2, shell=True, stdout=subprocess.PIPE,	stderr=subprocess.PIPE)
    z2 = z.stdout + z.stderr
    try:
    	conn.sendall(z2)
    except BrokenPipeError:
    	print('the connection was closed.')
Reply
#2
(May-15-2021, 06:03 AM)throwaway34 Wrote: In such as sudo, Clear, ping and so on I do not receive any feedback from the server end

I'm not sure, but:
  • sudo usually asks for the password on the terminal. But in this client-server construct there is no terminal.
  • clear clears the terminal screen. But what if there is no terminal?
  • ping does not end. It continues forever unless the -c option is used
Reply
#3
(May-15-2021, 08:28 AM)ibreeden Wrote:
(May-15-2021, 06:03 AM)throwaway34 Wrote: In such as sudo, Clear, ping and so on I do not receive any feedback from the server end

I'm not sure, but:
  • sudo usually asks for the password on the terminal. But in this client-server construct there is no terminal.
  • clear clears the terminal screen. But what if there is no terminal?
  • ping does not end. It continues forever unless the -c option is used

You dont get any output either from ping or sudo. :\
Reply
#4
when I run the server script on a separate PC. I cannot connect from the client end, all i get is a connection refused.
Reply
#5
What should I do?
Reply
#6
You say it does not work on a separate PC. So before it worked? Did it work when the server was a server? In that case it is most probably a firewall issue.
Reply
#7
(May-17-2021, 07:21 AM)ibreeden Wrote: You say it does not work on a separate PC. So before it worked? Did it work when the server was a server? In that case it is most probably a firewall issue.

It never worked before on a separate PC, that was the first attempt at running the two scripts on separate machines and maybe your right about the firewall part but, either way I still cannot get any output from certain commands/programs on the client side.
Reply
#8
(May-17-2021, 07:21 AM)ibreeden Wrote: You say it does not work on a separate PC. So before it worked? Did it work when the server was a server? In that case it is most probably a firewall issue.

When I do a Nmap scan to see if it(the server script) opens port 4444, no such port appears to be open.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 318 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Need some guidance on a script to ping a list of ip's cubangt 11 1,688 Aug-10-2023, 02:39 PM
Last Post: snippsat
  non-stop ping script kucingkembar 1 1,321 Aug-23-2022, 06:29 AM
Last Post: menator01
  sudo apt Not Working Dacdiver 11 18,266 Nov-09-2021, 05:48 PM
Last Post: jefsummers
  sudo RyAn 2 1,495 Nov-09-2021, 12:43 PM
Last Post: DeaD_EyE
  Problem executing a script on a remote host tester_V 3 2,398 Sep-26-2021, 04:25 AM
Last Post: tester_V
  Win32\ping.exe windows pops up -very annoying... tester_V 9 3,127 Aug-12-2021, 06:54 AM
Last Post: tester_V
  Looking for discord bot to make loop ping for address ip tinkode 0 1,789 Jul-26-2021, 03:51 PM
Last Post: tinkode
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,234 May-18-2021, 06:31 AM
Last Post: Skaperen
  Ping command using python 3.6.5 Martin2998 6 17,251 Apr-19-2021, 06:24 PM
Last Post: blazejwiecha

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020