Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to change interface/ip from GUI and with commandline with '-i' … #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
allow to change interface/ip from GUI and with commandline with '-i' …
…option

added check to validate local ip address
added .idea/ gitignore (PyCharm)
  • Loading branch information
Steven Barthen committed Dec 5, 2016
commit 4e7457fbcb2796fd83ec34fdd2a5bca56f43ae90
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.pyc
smon_decryptor.py
proxy.log
.idea/
2 changes: 1 addition & 1 deletion SWParser/gui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setupUi(self, MainWindow):
self.horizontalLayout.addWidget(self.label)
self.ipAddress = QtGui.QLineEdit(self.centralwidget)
self.ipAddress.setEnabled(True)
self.ipAddress.setReadOnly(True)
self.ipAddress.setReadOnly(False)
self.ipAddress.setObjectName(_fromUtf8("ipAddress"))
self.horizontalLayout.addWidget(self.ipAddress)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
Expand Down
2 changes: 1 addition & 1 deletion SWParser/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<property name="frame">
<bool>true</bool>
</property>
</widget>
Expand Down
8 changes: 8 additions & 0 deletions SWParser/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, ip, port, parent = None):

def run(self):
try:
SWProxy.is_ip_port_valid(self.ip, self.port)
logger.info("Running Proxy server at %s on port %s" % (self.ip, self.port))
p = SWProxy.HTTP(self.ip, self.port)
p.run()
Expand Down Expand Up @@ -53,6 +54,10 @@ def log(self, str):

def startStopProxy(self):
self.ui.proxyPort.setReadOnly(True)
self.ui.proxyPort.setEnabled(False)
self.ui.ipAddress.setReadOnly(True)
self.ui.ipAddress.setEnabled(False)

if self.proxy:
self.ui.startProxy.setText("Start Proxy Server")
self.ui.startProxy.setEnabled(False)
Expand All @@ -65,7 +70,10 @@ def startStopProxy(self):

def proxyStopped(self):
self.proxy = None
self.ui.ipAddress.setReadOnly(False)
self.ui.ipAddress.setEnabled(True)
self.ui.proxyPort.setReadOnly(False)
self.ui.proxyPort.setEnabled(True)
self.ui.startProxy.setEnabled(True)


Expand Down
31 changes: 27 additions & 4 deletions SWProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,20 @@ def _parse_response(self, response):
return plain, json.loads(plain)


def is_ip_port_valid(ip, port):
try:
socket.getaddrinfo(str(ip), port)
_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
_socket.bind((str(ip), port))
except:
raise
else:
_socket.close()


def get_external_ip():

my_ip = [[(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]][0]
return my_ip

Expand Down Expand Up @@ -123,15 +136,21 @@ def resource_path(relative_path):
return os.path.join(os.path.abspath("."), relative_path)


def start_proxy_server(options):
my_ip = get_external_ip()

def start_proxy_server(options):
if options.interface:
my_ip = options.interface
else:
my_ip = get_external_ip()

try:
is_ip_port_valid(my_ip, options.port)
print "Running Proxy server at {} on port {}".format(my_ip, options.port)
p = HTTP(my_ip, options.port)
p.run()
except KeyboardInterrupt:
pass
except socket.error:
logger.error("IP Address and/or Port invalid - can't start Proxy")


def parse_pcap(filename):
Expand Down Expand Up @@ -229,6 +248,7 @@ def parse_pcap(filename):
parser.add_argument('-d', '--debug', action="store_true", default=False)
parser.add_argument('-g', '--no-gui', action="store_true", default=False)
parser.add_argument('-p', '--port', type=int, default=8080)
parser.add_argument('-i', '--interface', type=str)
options = parser.parse_args()

# Set up logger
Expand Down Expand Up @@ -263,7 +283,10 @@ def parse_pcap(filename):
app_icon.addFile(icons_path + '48x48.png', QSize(48,48))
app_icon.addFile(icons_path + '256x256.png', QSize(256,256))
app.setWindowIcon(app_icon)
win = gui.MainWindow(get_external_ip(), options.port)
if options.interface:
win = gui.MainWindow(options.interface, options.port)
else:
win = gui.MainWindow(get_external_ip(), options.port)
logger.addHandler(gui.GuiLogHandler(win))
win.show()
sys.exit(app.exec_())