Question

Proxy script

  • 30 September 2020
  • 0 replies
  • 305 views

Userlevel 2
Badge +2

Hey guys,

I’m new at scripting/coding with python, I am trying to make a script that will automate adding a proxy, proxy whitelist and remove whitelists. 

This is what I have so far, but whenever it runs I get an error of “Error: Argument 'http-proxy' is specified multiple times.” 

import subprocess
import sys
add_whitelists = "ncli http-proxy add-to-whitelist target-type=IPV4_ADDRESS target="
whitelist_Ip = ["192.168.1.1", "200.200.1.1"]
login = "nutanix@192.168.1.50"
add_pxy = "ncli http-proxy add name=NPX5-proxy address=proxy.npx5.local port=8080 proxy-types=HTTPS"
list_proxy = "ncli http-proxy get-whitelist"
#ssh connection
ssh = subprocess.Popen(["ssh", "-i .ssh/id_rsa", login],
stdin =subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
bufsize=0)

# Send ssh commands to stdin
ssh.stdin.write(add_pxy)
for ip in whitelist_Ip:
ssh.stdin.write(add_whitelists + ip)
ssh.stdin.close()
# Fetch output
for line in ssh.stdout:
print(line.strip())

This topic has been closed for comments