Skip to content

Commit

Permalink
[Fix] Fix ssh tunnel always return 127.0.0.1
Browse files Browse the repository at this point in the history
修复ssh隧道始终返回127.0.0.1,改为动态获取本地地址
  • Loading branch information
bwcxyk authored Sep 14, 2024
1 parent 54bb3dc commit 1720601
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sql/utils/ssh_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sshtunnel import SSHTunnelForwarder
from paramiko import RSAKey
import io
import socket


class SSHConnection(object):
Expand Down Expand Up @@ -55,13 +56,20 @@ def __init__(
)
self.server.start()

# 动态获取本地IP
self.local_ip = self.get_local_ip()

def __del__(self):
self.server.close()

def get_local_ip(self):
"""
动态获取本地IP地址
"""
return socket.gethostbyname(socket.gethostname())

def get_ssh(self):
"""
获取ssh映射的端口
:param request:
:return:
获取ssh映射的本地IP和端口
"""
return "127.0.0.1", self.server.local_bind_port
return self.local_ip, self.server.local_bind_port

0 comments on commit 1720601

Please sign in to comment.