Last active
March 26, 2017 05:29
-
-
Save T31337/58f922220f12feb9bbf6da4abee45d66 to your computer and use it in GitHub Desktop.
Python Qt4 PortScanner
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 sys | |
import PyQt4.QtGui as QtGui | |
import socket | |
''' | |
Qt4 Version Of Python PortScanner (https://gist.github.com/T31337/93cf239fff8314b182e2) | |
License: | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/> | |
GUI PortScanner By: T31337 | |
Please Note, This Porgram Claims To Be "Not Responding" During Scan, | |
However, If You Wait, It Should Complete And Start Responding Again! | |
''' | |
class PortScanner(): | |
def __init__(self): | |
app = QtGui.QApplication(sys.argv) | |
self.scanner() | |
sys.exit(app.exec_()) | |
def pscan(self,port): | |
try: | |
target = self.server.text() | |
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
s.connect((target,port)) | |
return True | |
except: | |
return False | |
def scan(self): | |
if self.server.text() == "": | |
msg = QtGui.QMessageBox() | |
msg.setWindowTitle("PortScanner") | |
msg.setIcon(3) | |
msg.setText("ERROR:\r\nPlease Enter A Server URL Or IP ADDRESS") | |
msg.exec_() | |
pass | |
else: | |
msg = QtGui.QMessageBox() | |
msg.setWindowTitle("PortScanner") | |
msg.setText("Please Wait For Scan To Complete\r\nWindow May Appear Frozen During Scan\r\nResults Will Appear In Window When Done.") | |
msg.setIcon(2) | |
msg.exec_() | |
self.scanBtn.setEnabled(False) | |
self.message.setText("Scan For "+self.server.text()) | |
print('Scanning',self.server.text()) | |
for x in range(self.port.value(),self.port2.value()+1): | |
if self.pscan(x): | |
print('Port ',x,': Open!') | |
msg = "Port "+str(x)+" Is Open!" | |
self.message.append(msg) | |
else: | |
print('port ',x,': Closed!') | |
msg = "Port "+str(x)+" Is Closed!" | |
self.message.append(msg) | |
self.scanBtn.setEnabled(True) | |
def scanner(self): | |
win = QtGui.QDialog() | |
self.server = QtGui.QLineEdit() | |
self.port = QtGui.QSpinBox() | |
self.port.setMaximum(49151) | |
self.port.setMinimum(0) | |
self.port2 = QtGui.QSpinBox() | |
self.port2.setMaximum(49151) | |
self.port2.setMinimum(0) | |
self.message = QtGui.QTextEdit() | |
self.message.setReadOnly(True) | |
self.scanBtn = QtGui.QPushButton() | |
self.scanBtn.setText("Scan!") | |
self.scanBtn.clicked.connect(self.scan) | |
layout = QtGui.QGridLayout() | |
layout.setSpacing(10) | |
layout.addWidget(QtGui.QLabel("Server:"), 0, 0, 1, 1) | |
layout.addWidget(QtGui.QLabel("Starting Port:"), 2, 0, 1, 1) | |
layout.addWidget(QtGui.QLabel("Ending Port:"), 4, 0, 1, 1) | |
layout.addWidget(self.server, 0, 1, 2, 2) | |
layout.addWidget(self.port, 2, 1, 2, 2) | |
layout.addWidget(self.port2, 4, 1, 2, 2) | |
layout.addWidget(self.message, 6, 0, 2, 3) | |
layout.addWidget(self.scanBtn, 8, 0, 2, 3) | |
win.setWindowTitle("PortScanner") | |
win.setLayout(layout) | |
win.setGeometry(100, 100, 250, 350) | |
win.exec_() | |
sys.exit() | |
if __name__ == '__main__': | |
gui = PortScanner() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment