Hirdetés
- Kétezer eurós csomag lehet a Vivo X300 Ultra
- Xiaomi 15T Pro - a téma nincs lezárva
- Samsung Galaxy A56 - megbízható középszerűség
- Xiaomi 15T - reakció nélkül nincs egyensúly
- Samsung Galaxy S25 - végre van kicsi!
- Xiaomi 17 Ultra - jó az optikája
- Meglepően lassú az iOS 26 terjedése
- Android alkalmazások - szoftver kibeszélő topik
- Amazfit Active 2 NFC - jó kör
- Stílussal és friss szenzorokkal futott be a Huawei Watch GT 5
Ú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
- Kétezer eurós csomag lehet a Vivo X300 Ultra
- Revolut
- Mégis meglepi egy új GeForce-szal a rajongókat az NVIDIA?
- Milyen billentyűzetet vegyek?
- Nintendo Switch 2
- Intel Core Ultra 3, Core Ultra 5, Ultra 7, Ultra 9 "Arrow Lake" LGA 1851
- Magga: PLEX: multimédia az egész lakásban
- Samsung Galaxy Felhasználók OFF topicja
- Spórolós topik
- Gyúrósok ide!
- További aktív témák...
- új, bontatlan, iPhone 17E gyárilag kártya-független, apple világgaranciával
- Új, bontatlan - Apple MacBook Neo 13" A18 Pro 6CPU/5GPU/ 8GB/256GB Touch ID - Indigo/Silver
- Microsoft Surface Laptop 7 13,8" 2340x1560 touchscreen, Snapdragon X Elite, 32GB/1TB
- Biostar A55MLV Ver. 6.0 AMD FM1 alaplap
- Gyári dobozos Sapphire Radeon HD5450 PCI-E videokártya, szinte új!
- AKCIÓ! Motorola Edge 60 Pro 5G 512GB okostelefon garanciával hibátlan működéssel
- S21 256/8 dobozában
- ÚJ HP EliteBook 6 G1a Ryzen 5 PRO 230 4.9GHz 32GB DDR5 1TB FHD+ 16:10 már jobbik kijelző, gar 2028
- HP ProBook 445 G8 14" Ryzen 3 5400U, 8GB RAM, 256GB SSD, jó akku, számla, 6 hó gar
- Honor Magic6 Lite 256GB, Kártyafüggetlen, 1 Év Garanciával
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest

