0

Context

I am connected to a remote web server via port forwarding, I want to run a command on my local machine while connected

cutycapt --url=localhost:9000 --out=test.png --min-width=1366 --min-heigh=768

on my local machine to capture the web page presented via the web server (which has no graphical interface)

I've created a script that connects to the server, runs the command above but a 5.9kb blank png is returned, I believe the command is running on the web server rather than my own machine

Code

~$ cat Segment1.2v.py 
import paramiko
import time
import os
hosts_file = open('/etc/hosts')
IPs = []
for x in hosts_file:
   if "AN-54-Private" in x:
     IPs.append(x[:10])
hosts_file.close()
def DoBash(TARGET):
   os.system('cutycapt --url=localhost:9000 --out=test.png --min-width=1366 --min-heigh=768')
   time.sleep(15)
   return
test_file = open('IPs.txt')
for x in test_file:
   TARGET = x
   ssh = paramiko.SSHClient()
   ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
   ssh.connect(TARGET, username='nigel', key_filename='/home/Lima/.ssh/Alpha.ssh')
   print('Connected')
   DoBash(TARGET)
Danny Watson
  • 165
  • 5
  • 24
  • If the file `out.png` is being created on the local machine, then that is where cutycapt is running - paramiko can't capture filesystem operations of a shell command and redirect them back down the tunnel. This means that the issue is with `cutycapt` itself. – match Jan 21 '18 at 20:00
  • But cutycapt works fine when manually connected and then running the command from the CLI – Danny Watson Jan 21 '18 at 20:02
  • Does it work if you replace `DoBash(TARGET)` with `time.sleep(300)` and then manually run `cutycapt` while the script is holding the ssh connection open? I suspect that since your paramiko config says nothing about port-forwarding, you'll get an error. – match Jan 21 '18 at 20:04
  • match, I have port forward conditions in my config for ssh – Danny Watson Jan 21 '18 at 20:10
  • Nevertheless, is it actually set up when paramiko runs? What happens with my sleep test above? – match Jan 21 '18 at 20:16
  • figured it out, a proper 'doi' moment - I forgot to include http:// to the URL, I'm now figuring out how to dynamically rename files as cutycapt seems only for one file use – Danny Watson Jan 21 '18 at 20:24

0 Answers0