Spaces:
Running
Running
Update F.py
Browse files
F.py
CHANGED
|
@@ -1,38 +1,45 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
-
#
|
| 5 |
try:
|
| 6 |
import ngrok
|
|
|
|
|
|
|
|
|
|
| 7 |
except ImportError:
|
| 8 |
import subprocess
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
import ngrok
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
|
| 15 |
def lancer_tunnel():
|
| 16 |
try:
|
| 17 |
-
# Demande
|
| 18 |
port = int(input("Entrez le port local à exposer (ex: 80, 5000, 8080) : "))
|
| 19 |
except ValueError:
|
| 20 |
print("Erreur : Veuillez entrer un numéro de port valide.")
|
| 21 |
return
|
| 22 |
|
| 23 |
-
print("\nConnexion à ngrok...")
|
| 24 |
try:
|
| 25 |
-
#
|
|
|
|
|
|
|
|
|
|
| 26 |
listener = ngrok.forward(port, proto="http")
|
| 27 |
|
| 28 |
print("\n" + "="*50)
|
| 29 |
print(f" Tunnel activé avec succès !")
|
| 30 |
-
print(f" Port local : {port}")
|
| 31 |
print(f" URL publique : {listener.url()}")
|
| 32 |
print("="*50)
|
| 33 |
print("\nAppuyez sur Ctrl+C pour fermer le tunnel.")
|
| 34 |
|
| 35 |
-
# Maintien du tunnel
|
| 36 |
while True:
|
| 37 |
import time
|
| 38 |
time.sleep(1)
|
|
@@ -41,6 +48,8 @@ def lancer_tunnel():
|
|
| 41 |
print("\nFermeture du tunnel ngrok.")
|
| 42 |
except Exception as e:
|
| 43 |
print(f"\nErreur ngrok : {e}")
|
|
|
|
|
|
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
lancer_tunnel()
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
+
# Désinstalle l'ancien package problématique s'il est détecté et installe le bon SDK
|
| 5 |
try:
|
| 6 |
import ngrok
|
| 7 |
+
# Vérification de sécurité pour s'assurer qu'on a le bon module avec la fonction forward
|
| 8 |
+
if not hasattr(ngrok, "forward"):
|
| 9 |
+
raise ImportError
|
| 10 |
except ImportError:
|
| 11 |
import subprocess
|
| 12 |
+
print("Nettoyage et installation du bon SDK ngrok...")
|
| 13 |
+
subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "ngrok-api", "-y"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 14 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "ngrok"])
|
| 15 |
import ngrok
|
| 16 |
|
| 17 |
+
# Intégration de votre token d'authentification
|
| 18 |
+
AUTHTOKEN = "3IKq23oaCZLQzw7gyReFXkiHOtp_726tyz1mkexyHTHxUtwwb"
|
| 19 |
|
| 20 |
def lancer_tunnel():
|
| 21 |
try:
|
| 22 |
+
# Demande du port à l'utilisateur
|
| 23 |
port = int(input("Entrez le port local à exposer (ex: 80, 5000, 8080) : "))
|
| 24 |
except ValueError:
|
| 25 |
print("Erreur : Veuillez entrer un numéro de port valide.")
|
| 26 |
return
|
| 27 |
|
| 28 |
+
print(f"\nConnexion à ngrok pour exposer le port {port}...")
|
| 29 |
try:
|
| 30 |
+
# Configuration globale du token
|
| 31 |
+
ngrok.set_auth_token(AUTHTOKEN)
|
| 32 |
+
|
| 33 |
+
# Ouverture du tunnel vers localhost:port
|
| 34 |
listener = ngrok.forward(port, proto="http")
|
| 35 |
|
| 36 |
print("\n" + "="*50)
|
| 37 |
print(f" Tunnel activé avec succès !")
|
|
|
|
| 38 |
print(f" URL publique : {listener.url()}")
|
| 39 |
print("="*50)
|
| 40 |
print("\nAppuyez sur Ctrl+C pour fermer le tunnel.")
|
| 41 |
|
| 42 |
+
# Maintien du tunnel actif
|
| 43 |
while True:
|
| 44 |
import time
|
| 45 |
time.sleep(1)
|
|
|
|
| 48 |
print("\nFermeture du tunnel ngrok.")
|
| 49 |
except Exception as e:
|
| 50 |
print(f"\nErreur ngrok : {e}")
|
| 51 |
+
print("Si l'erreur persiste, relancez la commande de nettoyage dans votre terminal :")
|
| 52 |
+
print("pip uninstall ngrok ngrok-api -y && pip install ngrok")
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
lancer_tunnel()
|