Created
February 27, 2019 13:43
-
-
Save silverwolfceh/d1caa04a62e8d68cf585b1bac0180bdb to your computer and use it in GitHub Desktop.
Chilkat python ssh tunel example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chilkat2 | |
import requests | |
chilkatGlob = chilkat2.Global() | |
success = chilkatGlob.UnlockBundle("chilkat_key") | |
if (success != True): | |
print(chilkatGlob.LastErrorText) | |
sys.exit() | |
status = chilkatGlob.UnlockStatus | |
if (status == 2): | |
print("Unlocked using purchased unlock code.") | |
else: | |
print("Unlocked in trial mode.") | |
tunnel = chilkat2.SshTunnel() | |
sshHostname = "118.168.53.138" | |
sshPort = 22 | |
success = tunnel.Connect(sshHostname,sshPort) | |
if (success != True): | |
print(tunnel.LastErrorText) | |
sys.exit() | |
success = tunnel.AuthenticatePw("ubnt","ubnt") | |
if (success != True): | |
print(tunnel.LastErrorText) | |
sys.exit() | |
tunnel.DynamicPortForwarding = True | |
# Start the listen/accept thread to begin accepting SOCKS proxy client connections. | |
# Listen on port 1080. | |
success = tunnel.BeginAccepting(1235) | |
if (success != True): | |
print(tunnel.LastErrorText) | |
sys.exit() | |
print(tunnel.LastErrorText) | |
# For this example, let's do a simple HTTPS request: | |
url = "http://ip-api.com/json" | |
proxy ={ | |
'http': 'socks5://localhost:1235', | |
'https': 'socks5://localhost:1235', | |
} | |
res = requests.get(url, proxies=proxy) | |
print(res.text) | |
# Stop the background listen/accept thread: | |
waitForThreadExit = True | |
success = tunnel.StopAccepting(waitForThreadExit) | |
if (success != True): | |
print(tunnel.LastErrorText) | |
sys.exit() | |
# Close the SSH tunnel (would also kick any remaining connected clients). | |
success = tunnel.CloseTunnel(waitForThreadExit) | |
if (success != True): | |
print(tunnel.LastErrorText) | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://mmo4me.com/threads/share-ssh-theo-yeu-cau.389162/