forked from jofpin/trape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngrok.py
More file actions
executable file
·82 lines (72 loc) · 2.23 KB
/
ngrok.py
File metadata and controls
executable file
·82 lines (72 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#**
#
#########
# trape #
#########
#
# trape depends of this file
# For full copyright information this visit: https://github.com/jofpin/trape
#
# Copyright 2018 by Jose Pino (@jofpin) / <[email protected]>
#**
import sys
import os, platform
import subprocess
import socket
import os.path as path
from multiprocessing import Process
class ngrok(object):
def __init__(self, authtoken, port, nT, hash):
if authtoken:
self.token = authtoken
else:
print "Can't use Ngrok without a valid token"
system_type = os.name
system_name = platform.system()
system_architecture = platform.architecture()[0]
str_ngrok = './ngrok'
if "nt" in system_type:
str_ngrok = './ngrok.exe'
if path.exists(str_ngrok):
pass
else:
import urllib2
if "posix" in system_type:
if "arwin" in system_name:
if "64" in system_architecture:
download_link = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-amd64.zip"
else:
download_link = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-386.zip"
else:
if "64" in system_architecture:
download_link = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip"
else:
download_link = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-386.zip"
elif "nt" in system_type:
if "64" in system_architecture:
download_link = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-windows-amd64.zip"
else:
download_link = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-windows-386.zip"
else:
sys.exit(0)
filename = "ngrok.zip"
download = urllib2.urlopen(download_link)
saved_file=file(filename,"w")
saved_file.write(download.read())
saved_file.close()
result = subprocess.check_output(["unzip", filename])
os.remove(filename)
subprocess.check_output([str_ngrok, "authtoken", authtoken])
if nT > 0:
pNg = Process(target=start_ngrok, args=(str(port), hash, 1))
pNg.start()
def start_ngrok(port, hash, f=0):
if f != 0:
str_ngrok = './ngrok'
system_type = os.name
if "nt" in system_type:
str_ngrok = './ngrok.exe'
result = subprocess.check_output([str_ngrok, "http", port, '-log', hash + '.nlog'])
print result