Hirdetés
- Magisk
- Hivatalos a OnePlus 13 startdátuma
- Milyen hagyományos (nem okos-) telefont vegyek?
- Honor Magic8 Pro - bevált recept kölcsönvett hozzávalókkal
- Szívós, szép és kitartó az új OnePlus óra
- Realme GT Master Edition - mestermunka
- Telekom mobilszolgáltatások
- Neked tükröt, az iPhone Airnek emléket állít a Realme
- Apple Watch Ultra - első nekifutás
- Samsung Galaxy Watch (Tizen és Wear OS) ingyenes számlapok, kupon kódok
Új hozzászólás Aktív témák
-
válasz
cousin333
#1672
üzenetére
pontosan ott, hogy van egy ilyen kód
ssh_tunnel.py
# -*- coding: utf-8 -*-
import getpass
import sshtunnel
class jumpserver():
"""
this class realizes the jumpserver relay to get next to the db.
methods:
run(): starts the ssh tunnel.
disc(): closes the ssh tunnel.
"""
def __init__(self):
#read jumpserver and db connection path from file
#list
with open('ssh_tunnel.cfg') as ssh_tunnel_list:
ssh_tunnel_list = [x.strip('\n') for x in ssh_tunnel_list.readlines()]
#mapping connection data to string
self.ssh_tunnel_user = ssh_tunnel_list[1].replace('jumpserver user = ', '', 1)
self.ssh_tunnel_pw = ssh_tunnel_list[2].replace('jumpserver password = ', '', 1)
self.ssh_tunnel_ip = ssh_tunnel_list[3].replace('jumpserver ip = ', '', 1)
self.db_ip = ssh_tunnel_list[4].replace('db ip = ', '', 1)
while True:
if not self.ssh_tunnel_user:
self.ssh_tunnel_user = input("Input ssh tunner user:")
if self.ssh_tunnel_user:
break
else:
break
while True:
if not self.ssh_tunnel_pw:
self.ssh_tunnel_pw = getpass.getpass("Input ssh tunner password:")
if self.ssh_tunnel_pw:
break
else:
break
def run(self):
"""
starts the ssh tunnel.
"""
#starting tunnel
self.tunnel = sshtunnel.SSHTunnelForwarder((self.ssh_tunnel_ip, 22), ssh_username=self.ssh_tunnel_user, ssh_password=self.ssh_tunnel_pw, remote_bind_address=(self.db_ip, 1521), local_bind_address=('127.0.0.1', 1521))
try:
self.tunnel.start()
except:
print("connection to jumpserver", self.ssh_tunnel_ip, "as", self.ssh_tunnel_user, "failed.")
else:
#print("connection successful")
pass
return self.tunnel
def disc(self):
"""
closes the ssh tunnel.
"""
self.tunnel.stop()és van egy main.py, amelyik meghívja ebből az osztályból instalcol, és hívogatja a metódusait.
main.py
# -*- coding: utf-8 -*-
import ssh_tunnel
js = ssh_tunnel.jumpserver()
with js.run():
if js.run():
print("connection successful")
loop = True
while loop: ## While loop which will keep going until loop = False
if stuff_2_do:
do_stuff()
continue
elif:
os.system('cls||clear')
print("bye")
js.disc()
break # This will make the while loop to end as not value of loop is set to Falseés itt van az, hogy erre a main.py-re indítva egy debuggert, a js már nem jelenik meg, mint változó/object a debuggerben.
Új hozzászólás Aktív témák
- sziku69: Szólánc.
- Luck Dragon: Asszociációs játék. :)
- sziku69: Fűzzük össze a szavakat :)
- A Windowst és a macOS-t is váltaná a Google Aluminium OS
- Vicces képek
- Rezsicsökkentés, spórolás (fűtés, szigetelés, stb.)
- TCL LCD és LED TV-k
- One otthoni szolgáltatások (TV, internet, telefon)
- Tőzsde és gazdaság
- Magisk
- További aktív témák...
- Bomba ár! HP ProBook 430 G5 - i5-7GEN I 8GB I 128GB SSD I HDMI I 13,3" HD I Cam I W11 I Garancia!
- PlayStation Okosító Blu-ray lemezek - PS4 GoldHEN Loader / BD-JB Lapse és PS5 Auto Jailbreak AIO
- Xiaomi Mi Watch S1 Pro okosóra
- KÜLÖNLEGES RITKASÁG! VADIÚJ Microsoft Surface Pro 12 12" Snapdragon X Plus 16GB 512GB LEVENDULA 686g
- LG 27GS95QE - 27" OLED / QHD 2K / 240Hz & 0.03ms / 1000 Nits / NVIDIA G-Sync / AMD FreeSync
Állásajánlatok
Cég: Central PC számítógép és laptop szerviz - Pécs
Város: Pécs
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest


